Skip to content
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

Merged
merged 5 commits into from
Jan 31, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
77 changes: 43 additions & 34 deletions .eslintrc.js
Original file line number Diff line number Diff line change
Expand Up @@ -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": [
Copy link
Contributor Author

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

"error",
{
"examples/app/components/ComponentDeprecated":
"examples/app/components/Component",
Copy link

Choose a reason for hiding this comment

The 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.

Copy link
Contributor

Choose a reason for hiding this comment

The 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)",
}

Copy link
Contributor

Choose a reason for hiding this comment

The 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 components/ComponentDeprecated or just ComponentDeprecated

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Contributor Author

Choose a reason for hiding this comment

The 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',
},
}]
}
],
};
1 change: 1 addition & 0 deletions examples/app/components/ComponentDeprecated/index.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export const ComponentDeprecated = () => null;
4 changes: 4 additions & 0 deletions examples/app/modules/views/ExampleView.tsx
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 />;
15 changes: 8 additions & 7 deletions index.js
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"),
},
};
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "eslint-plugin-plentific",
"version": "1.7.3",
"version": "1.8.0",
"main": "index.js",
"author": "https://github.com/plentific/",
"license": "UNLICENSED",
Expand Down
40 changes: 40 additions & 0 deletions rules/no-deprecated-components.js
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],
},
});
}
},
};
},
};
Loading