@sumup-oss/eslint-plugin-circuit-ui
Version:
ESLint rules to lint Circuit UI.
122 lines (121 loc) • 4.33 kB
JavaScript
"use strict";
/**
* Copyright 2023, SumUp Ltd.
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
Object.defineProperty(exports, "__esModule", { value: true });
// We disable the rule in this file because we explicitly test invalid cases
/* eslint-disable @sumup-oss/circuit-ui/no-invalid-custom-properties */
const rule_tester_1 = require("@typescript-eslint/rule-tester");
const _1 = require(".");
// eslint-disable-next-line @typescript-eslint/no-unsafe-call
const ruleTester = new rule_tester_1.RuleTester({
parser: '@typescript-eslint/parser',
parserOptions: {
ecmaFeatures: {
jsx: true,
},
},
});
// eslint-disable-next-line @typescript-eslint/no-unsafe-call, @typescript-eslint/no-unsafe-member-access
ruleTester.run('component-lifecycle-imports', _1.componentLifecycleImports, {
valid: [
{
name: 'matching component import from unrelated package',
code: `
import { RangePicker } from 'material-ui';
`,
},
{
name: 'matching import from correct package',
code: `
import { RangePicker } from '@sumup-oss/circuit-ui/legacy';
`,
},
{
name: 'unrelated import from matching package',
code: `
import { Button } from '@sumup-oss/circuit-ui';
`,
},
{
name: 'unrelated import with matching local name',
code: `
import { Button as RangePicker } from '@sumup-oss/circuit-ui';
`,
},
],
invalid: [
{
name: '[Legacy] single import with single match',
code: `
import { RangePicker } from '@sumup-oss/circuit-ui';
`,
output: `
import { RangePicker } from '@sumup-oss/circuit-ui/legacy';
`,
errors: [{ messageId: 'refactor' }],
},
{
name: '[Legacy] single import with single match with local name',
code: `
import { RangePicker as RangeInput } from '@sumup-oss/circuit-ui';
`,
output: `
import { RangePicker as RangeInput } from '@sumup-oss/circuit-ui/legacy';
`,
errors: [{ messageId: 'refactor' }],
},
{
name: '[Legacy] multiple imports with single match',
code: `
import { RangePicker, Button } from '@sumup-oss/circuit-ui';
`,
output: `
import { Button } from '@sumup-oss/circuit-ui';import { RangePicker } from '@sumup-oss/circuit-ui/legacy';
`,
errors: [{ messageId: 'refactor' }],
},
{
name: '[Legacy] multiple imports with multiple matches',
code: `
import { RangePicker, RangePickerController } from '@sumup-oss/circuit-ui';
`,
// The other component will be migrated on the second pass.
output: `
import { RangePickerController } from '@sumup-oss/circuit-ui';import { RangePicker } from '@sumup-oss/circuit-ui/legacy';
`,
errors: [{ messageId: 'refactor' }, { messageId: 'refactor' }],
},
{
name: '[Legacy] single type import with single match',
code: `
import type { RangePickerProps } from '@sumup-oss/circuit-ui';
`,
output: `
import type { RangePickerProps } from '@sumup-oss/circuit-ui/legacy';
`,
errors: [{ messageId: 'refactor' }],
},
{
name: '[Experimental] single import with single match',
code: `
import { Calendar } from '@sumup-oss/circuit-ui/experimental';
`,
output: `
import { Calendar } from '@sumup-oss/circuit-ui';
`,
errors: [{ messageId: 'refactor' }],
},
],
});