PromucFlow_constructor/app/client/.eslintrc.js

170 lines
6.9 KiB
JavaScript
Raw Normal View History

// The `@type` comment improves auto-completion for VS Code users: https://github.com/appsmithorg/appsmith/pull/21602#discussion_r1144528505
/** @type {import('eslint').Linter.Config} */
fix(eslint): fix direct `remixicon` imports in `packages/design-system/*` (#24010) ## Description This PR: - moves the icon-related ESLint rules from to `eslintrc.base.json` – to make them apply to all packages - fixes direct `remixicon` imports surfaced by the change #### Type of change - Bug fix (non-breaking change which fixes an issue) ## Testing #### How Has This Been Tested? - [ ] Manual – smoke-tested that the dashboard and the editor open correctly - [ ] Jest - [ ] Cypress #### Test Plan > Add Testsmith test cases links that relate to this PR > > #### Issues raised during DP testing > Link issues raised during DP testing for better visiblity and tracking (copy link from comments dropped on this PR) > > > ## Checklist: #### Dev activity - [ ] My code follows the style guidelines of this project - [ ] I have performed a self-review of my own code - [ ] I have commented my code, particularly in hard-to-understand areas - [ ] I have made corresponding changes to the documentation - [ ] My changes generate no new warnings - [ ] I have added tests that prove my fix is effective or that my feature works - [ ] New and existing unit tests pass locally with my changes - [ ] PR is being merged under a feature flag #### QA activity: - [ ] [Speedbreak features](https://github.com/appsmithorg/TestSmith/wiki/Test-plan-implementation#speedbreaker-features-to-consider-for-every-change) have been covered - [ ] Test plan covers all impacted features and [areas of interest](https://github.com/appsmithorg/TestSmith/wiki/Guidelines-for-test-plans/_edit#areas-of-interest) - [ ] Test plan has been peer reviewed by project stakeholders and other QA members - [ ] Manually tested functionality on DP - [ ] We had an implementation alignment call with stakeholders post QA Round 2 - [ ] Cypress test cases have been added and approved by SDET/manual QA - [ ] Added `Test Plan Approved` label after Cypress tests were reviewed - [ ] Added `Test Plan Approved` label after JUnit tests were reviewed
2023-06-09 09:44:58 +00:00
const fs = require("fs");
const path = require("path");
const JSON5 = require("json5");
const baseEslintConfig = JSON5.parse(
fs.readFileSync(path.join(__dirname, "./.eslintrc.base.json"), "utf8"),
);
const baseNoRestrictedImports =
baseEslintConfig.rules["@typescript-eslint/no-restricted-imports"][1];
const eslintConfig = {
extends: ["./.eslintrc.base.json"],
rules: {
"testing-library/no-container": "off",
"testing-library/no-node-access": "off",
"testing-library/no-debugging-utils": "off",
"testing-library/prefer-screen-queries": "off",
"testing-library/render-result-naming-convention": "off",
"testing-library/no-unnecessary-act": "off",
"@typescript-eslint/prefer-nullish-coalescing": "off",
"@typescript-eslint/strict-boolean-expressions": "off",
"react/display-name": "off",
"react/prop-types": "off",
// `no-restricted-imports` is disabled, as recommended in https://typescript-eslint.io/rules/no-restricted-imports/.
// Please use @typescript-eslint/no-restricted-imports below instead.
"no-restricted-imports": "off",
"@typescript-eslint/no-restricted-imports": [
"error",
{
paths: [
fix(eslint): fix direct `remixicon` imports in `packages/design-system/*` (#24010) ## Description This PR: - moves the icon-related ESLint rules from to `eslintrc.base.json` – to make them apply to all packages - fixes direct `remixicon` imports surfaced by the change #### Type of change - Bug fix (non-breaking change which fixes an issue) ## Testing #### How Has This Been Tested? - [ ] Manual – smoke-tested that the dashboard and the editor open correctly - [ ] Jest - [ ] Cypress #### Test Plan > Add Testsmith test cases links that relate to this PR > > #### Issues raised during DP testing > Link issues raised during DP testing for better visiblity and tracking (copy link from comments dropped on this PR) > > > ## Checklist: #### Dev activity - [ ] My code follows the style guidelines of this project - [ ] I have performed a self-review of my own code - [ ] I have commented my code, particularly in hard-to-understand areas - [ ] I have made corresponding changes to the documentation - [ ] My changes generate no new warnings - [ ] I have added tests that prove my fix is effective or that my feature works - [ ] New and existing unit tests pass locally with my changes - [ ] PR is being merged under a feature flag #### QA activity: - [ ] [Speedbreak features](https://github.com/appsmithorg/TestSmith/wiki/Test-plan-implementation#speedbreaker-features-to-consider-for-every-change) have been covered - [ ] Test plan covers all impacted features and [areas of interest](https://github.com/appsmithorg/TestSmith/wiki/Guidelines-for-test-plans/_edit#areas-of-interest) - [ ] Test plan has been peer reviewed by project stakeholders and other QA members - [ ] Manually tested functionality on DP - [ ] We had an implementation alignment call with stakeholders post QA Round 2 - [ ] Cypress test cases have been added and approved by SDET/manual QA - [ ] Added `Test Plan Approved` label after Cypress tests were reviewed - [ ] Added `Test Plan Approved` label after JUnit tests were reviewed
2023-06-09 09:44:58 +00:00
...(baseNoRestrictedImports.paths ?? []),
{
name: "codemirror",
message:
"Reason: If you want to call CodeMirror.on(), CodeMirror.Pos(), or similar functions, please dont import CodeMirror directly. (This will cause it to be bundled in the main chunk.) Instead, assuming your function has access to CodeMirrors editor or doc, use getCodeMirrorNamespaceFromEditor() or getCodeMirrorNamespaceFromDoc() functions to get the CodeMirror namespace from the editor or the doc.",
// Allow type imports as they dont lead to bundling the dependency
allowTypeImports: true,
},
{
name: "lottie-web",
message:
"Reason: Please dont import lottie directly as its very large. Instead, use the utils/lazyLottie wrapper.",
// Allow type imports as they dont lead to bundling the dependency
allowTypeImports: true,
},
{
name: "sql-formatter",
importNames: ["format"],
message:
"Reason: Instead of `import { format }` (which bundles all formatting dialects), please import only dialects you need (e.g. `import { formatDialect, postgresql }`. See https://github.com/sql-formatter-org/sql-formatter/issues/452",
},
],
patterns: [
fix(eslint): fix direct `remixicon` imports in `packages/design-system/*` (#24010) ## Description This PR: - moves the icon-related ESLint rules from to `eslintrc.base.json` – to make them apply to all packages - fixes direct `remixicon` imports surfaced by the change #### Type of change - Bug fix (non-breaking change which fixes an issue) ## Testing #### How Has This Been Tested? - [ ] Manual – smoke-tested that the dashboard and the editor open correctly - [ ] Jest - [ ] Cypress #### Test Plan > Add Testsmith test cases links that relate to this PR > > #### Issues raised during DP testing > Link issues raised during DP testing for better visiblity and tracking (copy link from comments dropped on this PR) > > > ## Checklist: #### Dev activity - [ ] My code follows the style guidelines of this project - [ ] I have performed a self-review of my own code - [ ] I have commented my code, particularly in hard-to-understand areas - [ ] I have made corresponding changes to the documentation - [ ] My changes generate no new warnings - [ ] I have added tests that prove my fix is effective or that my feature works - [ ] New and existing unit tests pass locally with my changes - [ ] PR is being merged under a feature flag #### QA activity: - [ ] [Speedbreak features](https://github.com/appsmithorg/TestSmith/wiki/Test-plan-implementation#speedbreaker-features-to-consider-for-every-change) have been covered - [ ] Test plan covers all impacted features and [areas of interest](https://github.com/appsmithorg/TestSmith/wiki/Guidelines-for-test-plans/_edit#areas-of-interest) - [ ] Test plan has been peer reviewed by project stakeholders and other QA members - [ ] Manually tested functionality on DP - [ ] We had an implementation alignment call with stakeholders post QA Round 2 - [ ] Cypress test cases have been added and approved by SDET/manual QA - [ ] Added `Test Plan Approved` label after Cypress tests were reviewed - [ ] Added `Test Plan Approved` label after JUnit tests were reviewed
2023-06-09 09:44:58 +00:00
...(baseNoRestrictedImports.patterns ?? []),
chore: Adding eslint rule for @appsmith imports (#24207) ## Description Adding eslint rule for `@appsmith` imports to avoid a set of merge conflicts on community sync with the business edition repo. #### PR fixes following issue(s) Fixes [#24183](https://github.com/appsmithorg/appsmith/issues/24183) #### Type of change - Chore (housekeeping or task changes that don't impact user perception) ## Testing #### How Has This Been Tested? - [x] Manual - [ ] Jest - [ ] Cypress ## Checklist: #### Dev activity - [x] My code follows the style guidelines of this project - [x] I have performed a self-review of my own code - [x] I have commented my code, particularly in hard-to-understand areas - [ ] I have made corresponding changes to the documentation - [x] My changes generate no new warnings - [ ] I have added tests that prove my fix is effective or that my feature works - [x] New and existing unit tests pass locally with my changes - [ ] PR is being merged under a feature flag #### QA activity: - [ ] [Speedbreak features](https://github.com/appsmithorg/TestSmith/wiki/Test-plan-implementation#speedbreaker-features-to-consider-for-every-change) have been covered - [ ] Test plan covers all impacted features and [areas of interest](https://github.com/appsmithorg/TestSmith/wiki/Guidelines-for-test-plans/_edit#areas-of-interest) - [ ] Test plan has been peer reviewed by project stakeholders and other QA members - [ ] Manually tested functionality on DP - [ ] We had an implementation alignment call with stakeholders post QA Round 2 - [ ] Cypress test cases have been added and approved by SDET/manual QA - [ ] Added `Test Plan Approved` label after Cypress tests were reviewed - [ ] Added `Test Plan Approved` label after JUnit tests were reviewed
2023-06-07 14:09:17 +00:00
{
group: ["**/ce/*"],
message: "Reason: Please use @appsmith import instead.",
},
],
},
],
"no-restricted-syntax": [
// Annoyingly, the `no-restricted-imports` rule doesnt allow to restrict imports of
// `editorComponents/CodeEditor` but not `editorComponents/CodeEditor/*`: https://stackoverflow.com/q/64995811/1192426
// So were using `no-restricted-syntax` instead.
"error",
{
// Match all
// - `import` statements
// - that are not `import type` statements we allow type imports as they dont lead to bundling the dependency
// - that import `editorComponents/CodeEditor` or `editorComponents/CodeEditor/index` but not `editorComponents/CodeEditor/<anything else>`
// Note: using `\\u002F` instead of `/` due to https://eslint.org/docs/latest/extend/selectors#known-issues
selector:
"ImportDeclaration[importKind!='type'][source.value=/editorComponents\\u002FCodeEditor(\\u002Findex)?$/]",
message:
"Please dont import CodeEditor directly this will cause it to be bundled in the main chunk. Instead, use the LazyCodeEditor component.",
},
// Annoyingly, no-restricted-imports follows the gitignore exclude syntax,
// so theres no way to exclude all @uppy/* but not @uppy/*/*.css imports:
// https://github.com/eslint/eslint/issues/16927
{
// Match all
// - `import` statements
// - that are not `import type` statements we allow type imports as they dont lead to bundling the dependency
// - that import `@uppy/*` unless the `*` part ends with `.css`
// Note: using `\\u002F` instead of `/` due to https://eslint.org/docs/latest/extend/selectors#known-issues
selector:
"ImportDeclaration[importKind!='type'][source.value=/^@uppy\\u002F(?!.*.css$)/]",
message:
"Please dont import Uppy directly. End users rarely use Uppy (e.g. only when they need to upload a file) but Uppy bundles ~200 kB of JS. Please import it lazily instead.",
},
],
},
};
eslintConfig.overrides = [
// For CodeEditor, disable CodeEditor- and CodeMirror-specific import rules
{
files: ["**/components/editorComponents/CodeEditor/**/*"],
rules: {
"@typescript-eslint/no-restricted-imports":
getRestrictedImportsOverrideForCodeEditor(eslintConfig),
"no-restricted-syntax":
getRestrictedSyntaxOverrideForCodeEditor(eslintConfig),
},
},
chore: Overriding the import @appsmith eslint rule on EE folder (#24228) ## Description Overriding the import @appsmith eslint rule on EE folder #### PR fixes following issue(s) Fixes [#24183](https://github.com/appsmithorg/appsmith/issues/24183) #### Type of change - Chore (housekeeping or task changes that don't impact user perception) ## Testing #### How Has This Been Tested? - [x] Manual - [ ] Jest - [ ] Cypress ## Checklist: #### Dev activity - [x] My code follows the style guidelines of this project - [x] I have performed a self-review of my own code - [x] I have commented my code, particularly in hard-to-understand areas - [ ] I have made corresponding changes to the documentation - [x] My changes generate no new warnings - [ ] I have added tests that prove my fix is effective or that my feature works - [x] New and existing unit tests pass locally with my changes - [ ] PR is being merged under a feature flag #### QA activity: - [ ] [Speedbreak features](https://github.com/appsmithorg/TestSmith/wiki/Test-plan-implementation#speedbreaker-features-to-consider-for-every-change) have been covered - [ ] Test plan covers all impacted features and [areas of interest](https://github.com/appsmithorg/TestSmith/wiki/Guidelines-for-test-plans/_edit#areas-of-interest) - [ ] Test plan has been peer reviewed by project stakeholders and other QA members - [ ] Manually tested functionality on DP - [ ] We had an implementation alignment call with stakeholders post QA Round 2 - [ ] Cypress test cases have been added and approved by SDET/manual QA - [ ] Added `Test Plan Approved` label after Cypress tests were reviewed - [ ] Added `Test Plan Approved` label after JUnit tests were reviewed
2023-06-08 06:39:00 +00:00
{
files: ["**/ee/**/*"],
rules: {
...eslintConfig.rules,
"@typescript-eslint/no-restricted-imports":
getRestrictedImportsOverrideForEE(eslintConfig),
},
},
];
function getRestrictedImportsOverrideForCodeEditor(eslintConfig) {
const [errorLevel, existingRules] =
eslintConfig.rules["@typescript-eslint/no-restricted-imports"];
const newPatterns = (existingRules.patterns ?? []).filter(
(i) => i.group[0] !== "**/components/editorComponents/CodeEditor",
);
const newPaths = (existingRules.paths ?? []).filter(
(i) => i.name !== "codemirror",
);
if (newPatterns.length === 0 && newPaths.length === 0) {
return ["off"];
}
return [errorLevel, { patterns: newPatterns, paths: newPaths }];
}
function getRestrictedSyntaxOverrideForCodeEditor(eslintConfig) {
const [errorLevel, ...existingRules] =
eslintConfig.rules["no-restricted-syntax"];
const newRules = existingRules.filter(
(i) =>
i.selector !==
"ImportDeclaration[source.value=/editorComponents\\u002FCodeEditor(\\u002Findex)?$/]",
);
if (newRules.length === 0) {
return ["off"];
}
return [errorLevel, ...newRules];
}
chore: Overriding the import @appsmith eslint rule on EE folder (#24228) ## Description Overriding the import @appsmith eslint rule on EE folder #### PR fixes following issue(s) Fixes [#24183](https://github.com/appsmithorg/appsmith/issues/24183) #### Type of change - Chore (housekeeping or task changes that don't impact user perception) ## Testing #### How Has This Been Tested? - [x] Manual - [ ] Jest - [ ] Cypress ## Checklist: #### Dev activity - [x] My code follows the style guidelines of this project - [x] I have performed a self-review of my own code - [x] I have commented my code, particularly in hard-to-understand areas - [ ] I have made corresponding changes to the documentation - [x] My changes generate no new warnings - [ ] I have added tests that prove my fix is effective or that my feature works - [x] New and existing unit tests pass locally with my changes - [ ] PR is being merged under a feature flag #### QA activity: - [ ] [Speedbreak features](https://github.com/appsmithorg/TestSmith/wiki/Test-plan-implementation#speedbreaker-features-to-consider-for-every-change) have been covered - [ ] Test plan covers all impacted features and [areas of interest](https://github.com/appsmithorg/TestSmith/wiki/Guidelines-for-test-plans/_edit#areas-of-interest) - [ ] Test plan has been peer reviewed by project stakeholders and other QA members - [ ] Manually tested functionality on DP - [ ] We had an implementation alignment call with stakeholders post QA Round 2 - [ ] Cypress test cases have been added and approved by SDET/manual QA - [ ] Added `Test Plan Approved` label after Cypress tests were reviewed - [ ] Added `Test Plan Approved` label after JUnit tests were reviewed
2023-06-08 06:39:00 +00:00
function getRestrictedImportsOverrideForEE(eslintConfig) {
const [errorLevel, existingRules] =
eslintConfig.rules["@typescript-eslint/no-restricted-imports"];
const newPatterns = (existingRules.patterns ?? []).filter(
(i) => i.group[0] !== "**/ce/*",
);
if (newPatterns.length === 0) {
return ["off"];
}
return [errorLevel, { paths: existingRules.paths, patterns: newPatterns }];
}
module.exports = eslintConfig;