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

Reorganize no-restricted-imports for easy override by the extension #230

Merged
merged 2 commits into from
Feb 28, 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
85 changes: 2 additions & 83 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -53,68 +53,9 @@ const config = {
},
],

"no-restricted-syntax": ["error", ...require("./no-restricted-syntax")],
"no-restricted-imports": ["error", require("./no-restricted-imports")],

"no-restricted-imports": [
"error",
{
// Documentation: https://eslint.org/docs/rules/no-restricted-imports#options
paths: [
{
name: "lodash",
importNames: ["lowerCase"],
message: "Use the native String.toLowerCase method instead.",
},
],
patterns: [
{
group: ["*/__mocks__/*"],
message:
"Mocks should not be imported directly, they’re automatically picked up where needed.",
},
{
group: ["lodash/*"],
message: 'You can import "lodash" instead of "lodash/*".',
},
{
group: ["immer/*"],
importNames: ["WritableDraft"],
message: 'Use this instead: import { type Draft } from "immer"',
},
{
group: ["react-spinners"],
message:
"Use the local <Loader/> component instead, it's already centered.",
},
{
group: ["react-bootstrap/*", "!react-bootstrap/types"],
message:
'You can import "react-bootstrap" instead of "react-bootstrap/*".',
},
{
group: ["../*"],
message:
'Use root-based imports (`import "@/something"`) instead of relative imports.',
},
{
group: ["formik"],
importNames: ["Form", "Formik"],
message: 'Use this instead: import "@/components/form/Form"',
},
{
group: ["react-bootstrap"],
importNames: ["Form"],
message: 'Use this instead: import "@/components/form/Form"',
},
{
group: ["webext-detect-page"],
importNames: ["isDevToolsPage"],
message:
'Use this instead: import { isPageEditor } from "@/utils/expectContext";',
},
],
},
],
"no-restricted-syntax": ["error", ...require("./no-restricted-syntax")],

// Avoid imports with side effects
"import/no-unassigned-import": [
Expand Down Expand Up @@ -324,26 +265,4 @@ const config = {
],
};

// Add override this way because it depends on the object above
config.overrides.push({
files: ["src/*"],
rules: {
"no-restricted-imports": [
"error",
{
// Documentation: https://eslint.org/docs/rules/no-restricted-imports#options
patterns: [
// Extend the existing patterns
...config.rules["no-restricted-imports"][1].patterns,
{
group: ["./*"],
message:
'Use root-based imports (`import "@/something"`) instead of relative imports.',
},
],
},
],
},
});

module.exports = config;
57 changes: 57 additions & 0 deletions no-restricted-imports.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
module.exports = {
// Documentation: https://eslint.org/docs/rules/no-restricted-imports#options
paths: [
{
name: "lodash",
importNames: ["lowerCase"],
message: "Use the native String.toLowerCase method instead.",
},
],
patterns: [
{
group: ["*/__mocks__/*"],
message:
"Mocks should not be imported directly, they’re automatically picked up where needed.",
},
{
group: ["lodash/*"],
message: 'You can import "lodash" instead of "lodash/*".',
},
{
group: ["immer/*"],
importNames: ["WritableDraft"],
message: 'Use this instead: import { type Draft } from "immer"',
},
{
group: ["react-spinners"],
message:
"Use the local <Loader/> component instead, it's already centered.",
},
{
group: ["react-bootstrap/*", "!react-bootstrap/types"],
message:
'You can import "react-bootstrap" instead of "react-bootstrap/*".',
},
{
group: ["../*"],
message:
'Use root-based imports (`import "@/something"`) instead of relative imports.',
},
{
group: ["formik"],
importNames: ["Form", "Formik"],
message: 'Use this instead: import "@/components/form/Form"',
},
{
group: ["react-bootstrap"],
importNames: ["Form"],
message: 'Use this instead: import "@/components/form/Form"',
},
{
group: ["webext-detect-page"],
importNames: ["isDevToolsPage"],
message:
'Use this instead: import { isPageEditor } from "@/utils/expectContext";',
},
],
};
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
"development.js",
"tests.js",
"no-restricted-syntax.js",
"no-restricted-imports.js",
"xoPluginsConfig.js"
],
"scripts": {
Expand Down