Skip to content

Commit

Permalink
Merge pull request #21 from plentific/kp/FEUIUX-315
Browse files Browse the repository at this point in the history
FEUIUX-407 feat: add `no-deprecated-components` rule
  • Loading branch information
kubaprzetakiewicz authored Jan 31, 2024
2 parents adce433 + 0b3f7f6 commit b84eca6
Show file tree
Hide file tree
Showing 6 changed files with 97 additions and 42 deletions.
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": [
"error",
{
"examples/app/components/ComponentDeprecated":
"examples/app/components/Component",
},
],
"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],
},
});
}
},
};
},
};

0 comments on commit b84eca6

Please sign in to comment.