-
-
Notifications
You must be signed in to change notification settings - Fork 76
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat!: rework migrate package to support custom from from and to
- Loading branch information
Showing
9 changed files
with
369 additions
and
139 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,38 +1,11 @@ | ||
import migrate from './migrate' | ||
import migrate from './rules/migrate' | ||
import migrateTs from './rules/migrate-ts' | ||
import migrateJs from './rules/migrate-js' | ||
|
||
export default { | ||
rules: { | ||
rules: migrate, | ||
}, | ||
configs: { | ||
recommended: { | ||
plugins: [ | ||
'@stylistic/migrate', | ||
], | ||
overrides: [ | ||
{ | ||
files: [ | ||
'.eslintrc.js', | ||
'.eslintrc.cjs', | ||
'.eslintrc.json', | ||
'eslintrc.js', | ||
'eslintrc.cjs', | ||
'eslintrc.json', | ||
'eslint.config.js', | ||
'eslint.config.cjs', | ||
'eslint.config.ts', | ||
'**/eslint-config-*/index.js', | ||
'**/eslint-config-*/src/index.js', | ||
'**/eslint-config-*/src/index.ts', | ||
'**/eslint-config/index.js', | ||
'**/eslint-config/src/index.js', | ||
'**/eslint-config/src/index.ts', | ||
], | ||
rules: { | ||
'@stylistic/migrate/rules': 'error', | ||
}, | ||
}, | ||
], | ||
}, | ||
migrate, | ||
'migrate-ts': migrateTs, | ||
'migrate-js': migrateJs, | ||
}, | ||
} |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
import { packages } from '@eslint-stylistic/metadata' | ||
import { createEslintRule, createRuleListener } from '../shared' | ||
import type { MigrationOption } from '../shared' | ||
|
||
const js = packages.find(p => p.shortId === 'js')! | ||
|
||
export default createEslintRule<[MigrationOption], 'migrate'>({ | ||
name: 'migrate-js', | ||
meta: { | ||
type: 'suggestion', | ||
docs: { | ||
description: 'Migrate built-in stylistic rules to @stylistic/js rules', | ||
}, | ||
fixable: 'code', | ||
messages: { | ||
migrate: 'Should migrate stylistic rule \'{{from}}\' to \'{{to}}\'', | ||
}, | ||
schema: undefined!, | ||
}, | ||
defaultOptions: [{ | ||
namespaceFrom: '', | ||
namespaceTo: '@stylistic/js', | ||
}], | ||
create(context, options) { | ||
return createRuleListener( | ||
context as any, | ||
[{ | ||
namespaceFrom: options[0].namespaceFrom, | ||
namespaceTo: options[0].namespaceTo, | ||
rules: js.rules, | ||
}], | ||
) | ||
}, | ||
}) |
42 changes: 42 additions & 0 deletions
42
packages/eslint-plugin-migrate/src/rules/migrate-ts.test.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
import { RuleTester } from '@typescript-eslint/rule-tester' | ||
import rule from './migrate-ts' | ||
|
||
const valids = [ | ||
{ | ||
rules: { | ||
'foo': 'error', | ||
'@stylistic/indent': 'error', | ||
}, | ||
}, | ||
{ | ||
rules: { | ||
indent: 'error', | ||
}, | ||
}, | ||
].map(json => `module.exports = ${JSON.stringify(json, null, 2)}`) | ||
|
||
const invalids = [ | ||
[ | ||
{ | ||
rules: { | ||
'@typescript-eslint/indent': 'error', | ||
}, | ||
}, | ||
{ | ||
rules: { | ||
'@stylistic/ts/indent': 'error', | ||
}, | ||
}, | ||
], | ||
].map(([from, to]) => ({ | ||
code: `module.exports = ${JSON.stringify(from, null, 2)}`, | ||
output: `module.exports = ${JSON.stringify(to, null, 2)}`, | ||
errors: [{ messageId: 'migrate' }], | ||
})) | ||
|
||
const ruleTester: RuleTester = new RuleTester() | ||
|
||
ruleTester.run('migrate-ts', rule as any, { | ||
valid: valids, | ||
invalid: invalids, | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
import { packages } from '@eslint-stylistic/metadata' | ||
import type { MigrationOption } from '../shared' | ||
import { createEslintRule, createRuleListener } from '../shared' | ||
|
||
const ts = packages.find(p => p.shortId === 'ts')! | ||
|
||
export default createEslintRule<[MigrationOption], 'migrate'>({ | ||
name: 'migrate-ts', | ||
meta: { | ||
type: 'suggestion', | ||
docs: { | ||
description: 'Migrate `@typescript-eslint` stylistic rules to `@stylistic/ts` rules', | ||
}, | ||
fixable: 'code', | ||
messages: { | ||
migrate: 'Should migrate stylistic rule \'{{from}}\' to \'{{to}}\'', | ||
}, | ||
schema: undefined!, | ||
}, | ||
defaultOptions: [{ | ||
namespaceFrom: '@typescript-eslint', | ||
namespaceTo: '@stylistic/ts', | ||
}], | ||
create(context, options) { | ||
return createRuleListener( | ||
context as any, | ||
[{ | ||
namespaceFrom: options[0].namespaceFrom, | ||
namespaceTo: options[0].namespaceTo, | ||
rules: ts.rules, | ||
}], | ||
) | ||
}, | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,65 @@ | ||
import { RuleTester } from '@typescript-eslint/rule-tester' | ||
import rule from './migrate' | ||
|
||
const valids = [ | ||
{ | ||
rules: { | ||
'foo': 'error', | ||
'@stylistic/indent': 'error', | ||
}, | ||
}, | ||
].map(json => `module.exports = ${JSON.stringify(json, null, 2)}`) | ||
|
||
const invalids = [ | ||
[ | ||
{ | ||
rules: { | ||
indent: 'error', | ||
}, | ||
}, | ||
{ | ||
rules: { | ||
'@stylistic/indent': 'error', | ||
}, | ||
}, | ||
], | ||
[ | ||
{ | ||
rules: { | ||
'@typescript-eslint/indent': 'error', | ||
}, | ||
}, | ||
{ | ||
rules: { | ||
'@stylistic/indent': 'error', | ||
}, | ||
}, | ||
], | ||
[ | ||
{ | ||
rules: { | ||
'@typescript-eslint/indent': 'error', | ||
}, | ||
}, | ||
{ | ||
rules: { | ||
'style/indent': 'error', | ||
}, | ||
}, | ||
{ | ||
namespaceTo: 'style', | ||
}, | ||
], | ||
].map(([from, to, options]) => ({ | ||
code: `module.exports = ${JSON.stringify(from, null, 2)}`, | ||
output: `module.exports = ${JSON.stringify(to, null, 2)}`, | ||
errors: [{ messageId: 'migrate' }], | ||
options: [options] as any, | ||
})) | ||
|
||
const ruleTester: RuleTester = new RuleTester() | ||
|
||
ruleTester.run('migrate', rule as any, { | ||
valid: valids, | ||
invalid: invalids, | ||
}) |
Oops, something went wrong.