-
Notifications
You must be signed in to change notification settings - Fork 1
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
FEUIUX-407 feat: add no-deprecated-components
rule
#21
Changes from all commits
7b36ff0
9ce3ac3
d707759
1d9477e
0b3f7f6
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -7,45 +7,54 @@ const noCyclicModulesImportsConfig = ` | |
` | ||
|
||
module.exports = { | ||
extends: [ | ||
'plugin:eslint-comments/recommended', | ||
], | ||
plugins: [ | ||
'plentific' | ||
], | ||
extends: ["plugin:eslint-comments/recommended"], | ||
plugins: ["plentific"], | ||
|
||
rules: { | ||
'eslint-comments/disable-enable-pair': ['error', { allowWholeFile: true }], | ||
'eslint-comments/no-unused-disable': 'error', | ||
'plentific/debug': 'error', | ||
'plentific/no-concurrent-async': 'error', | ||
'plentific/no-cyclic-modules-imports': ['error', { config: noCyclicModulesImportsConfig }], | ||
'plentific/no-trailing-slash': 'error', | ||
'plentific/no-window-location-replace': 'error', | ||
"eslint-comments/disable-enable-pair": ["error", { allowWholeFile: true }], | ||
"eslint-comments/no-unused-disable": "error", | ||
"plentific/debug": "error", | ||
"plentific/no-concurrent-async": "error", | ||
"plentific/no-deprecated-components": [ | ||
"error", | ||
{ | ||
"examples/app/components/ComponentDeprecated": | ||
"examples/app/components/Component", | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Leaving it as suggestion here, potentially this can be extended to an array, where as a second optional value we can provide a link to storybook where detailed examples can help developers with migrations. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I was thinking about that as well but the value is quite universal you can even do {
"examples/app/components/ComponentDeprecated":
"examples/app/components/Component (see documentation on https://bla.com)",
} There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. but probably i'd won't do exact matching because if deprecated component will be moved, and somebody forget to adjust the rule, it will stop matching, maybe so if we do matching like import ends with, you can still do exact match or just sub matching There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. yeah, as @rostislav-simonik-plc mentioned - i did similar in the There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. i wouldn't lock it into Storybook, because not every substitution is UX/UI/Storybook/Blueprint-related |
||
}, | ||
], | ||
"plentific/no-cyclic-modules-imports": [ | ||
"error", | ||
{ config: noCyclicModulesImportsConfig }, | ||
], | ||
"plentific/no-trailing-slash": "error", | ||
"plentific/no-window-location-replace": "error", | ||
}, | ||
|
||
overrides: [{ | ||
files: ['examples/**/*.js{x,}'], | ||
parser: '@babel/eslint-parser', | ||
parserOptions: { | ||
ecmaFeatures: { | ||
jsx: true, | ||
legacyDecorators: true, | ||
overrides: [ | ||
{ | ||
files: ["examples/**/*.js{x,}"], | ||
parser: "@babel/eslint-parser", | ||
parserOptions: { | ||
ecmaFeatures: { | ||
jsx: true, | ||
legacyDecorators: true, | ||
}, | ||
}, | ||
rules: { | ||
quotes: [2, "single"], | ||
}, | ||
}, | ||
rules: { | ||
quotes: [2, 'single'] | ||
} | ||
}, { | ||
files: ['examples/**/*.ts{x,}'], | ||
parser: '@typescript-eslint/parser', | ||
parserOptions: { | ||
ecmaFeatures: { | ||
jsx: true, | ||
{ | ||
files: ["examples/**/*.ts{x,}"], | ||
parser: "@typescript-eslint/parser", | ||
parserOptions: { | ||
ecmaFeatures: { | ||
jsx: true, | ||
}, | ||
ecmaVersion: 2018, | ||
sourceType: "module", | ||
project: "./tsconfig.json", | ||
}, | ||
ecmaVersion: 2018, | ||
sourceType: 'module', | ||
project: './tsconfig.json', | ||
}, | ||
}] | ||
} | ||
], | ||
}; |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
export const ComponentDeprecated = () => null; |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
// eslint-disable-next-line plentific/no-deprecated-components | ||
import { ComponentDeprecated } from "examples/app/components/ComponentDeprecated"; | ||
|
||
export const ExampleView = () => <ComponentDeprecated />; |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,9 +1,10 @@ | ||
module.exports = { | ||
rules: { | ||
'debug': require('./rules/debug'), | ||
'no-concurrent-async': require('./rules/no-concurrent-async'), | ||
'no-cyclic-modules-imports': require('./rules/no-cyclic-modules-imports'), | ||
'no-trailing-slash': require('./rules/no-trailing-slash'), | ||
'no-window-location-replace': require('./rules/no-window-location-replace'), | ||
} | ||
} | ||
debug: require("./rules/debug"), | ||
"no-concurrent-async": require("./rules/no-concurrent-async"), | ||
"no-deprecated-components": require("./rules/no-deprecated-components"), | ||
"no-cyclic-modules-imports": require("./rules/no-cyclic-modules-imports"), | ||
"no-trailing-slash": require("./rules/no-trailing-slash"), | ||
"no-window-location-replace": require("./rules/no-window-location-replace"), | ||
}, | ||
}; |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
module.exports = { | ||
meta: { | ||
type: "problem", | ||
docs: { | ||
description: | ||
"Prevent importing deprecated component based on a configurable list of restricted paths.", | ||
}, | ||
schema: [ | ||
{ | ||
type: "object", | ||
additionalProperties: { | ||
type: "string", | ||
}, | ||
}, | ||
], | ||
messages: { | ||
deprecatedComponentImport: | ||
'Components and utils under "{{path}}" are considered deprecated, please migrate the usage to "{{replacement}}". If this rule is blocking you and you have to disable it, please include a comment with JIRA ticket and the reason for not doing the migration.', | ||
}, | ||
}, | ||
|
||
create(context) { | ||
const restrictedPaths = context.options[0] || {}; | ||
|
||
return { | ||
ImportDeclaration(node) { | ||
if (restrictedPaths.hasOwnProperty(node.source.value)) { | ||
context.report({ | ||
node, | ||
messageId: "deprecatedComponentImport", | ||
data: { | ||
path: node.source.value, | ||
replacement: restrictedPaths[node.source.value], | ||
}, | ||
}); | ||
} | ||
}, | ||
}; | ||
}, | ||
}; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
note: the only change in this file, everything else is prettified