@qlik/eslint-config 1.4.28 → 2.0.0-next.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,7 +1,7 @@
1
1
  // @ts-check
2
2
 
3
3
  /**
4
- * @satisfies {import("../../types/index.js").ESLintFlatConfig["rules"]}
4
+ * @satisfies {import("../../../types/index.js").ESLintFlatConfig["rules"]}
5
5
  *
6
6
  * eslint-plugin-import-x package https://github.com/un-ts/eslint-plugin-import-x/blob/master/README.md
7
7
  */
@@ -12,22 +12,13 @@ const rules = {
12
12
  /* -------------------------------------------------------------------------- */
13
13
  // ensure imports point to files/modules that can be resolved
14
14
  // https://github.com/un-ts/eslint-plugin-import-x/blob/master/docs/rules/no-unresolved.md
15
- "import-x/no-unresolved": ["error", { commonjs: true, caseSensitive: true }],
16
- // ensure named imports coupled with named exports
17
- // https://github.com/un-ts/eslint-plugin-import-x/blob/master/docs/rules/named.md#when-not-to-use-it
18
- "import-x/named": "error",
15
+ "import-x/no-unresolved": ["error", { commonjs: true }],
19
16
  /* -------------------------------------------------------------------------- */
20
17
  /* Helpful warnings: */
21
18
  /* -------------------------------------------------------------------------- */
22
- // disallow invalid exports, e.g. multiple defaults
23
- // https://github.com/un-ts/eslint-plugin-import-x/blob/master/docs/rules/export.md
24
- "import-x/export": "error",
25
19
  // do not allow a default import name to match a named export
26
20
  // https://github.com/un-ts/eslint-plugin-import-x/blob/master/docs/rules/no-named-as-default.md
27
21
  "import-x/no-named-as-default": "error",
28
- // warn on accessing default export property names that are also named exports
29
- // https://github.com/un-ts/eslint-plugin-import-x/blob/master/docs/rules/no-named-as-default-member.md
30
- "import-x/no-named-as-default-member": "off",
31
22
  // disallow use of jsdoc-marked-deprecated imports
32
23
  // https://github.com/un-ts/eslint-plugin-import-x/blob/master/docs/rules/no-deprecated.md
33
24
  "import-x/no-deprecated": "warn",
@@ -47,6 +38,7 @@ const rules = {
47
38
  "tests/**", // also common npm pattern
48
39
  "spec/**", // mocha, rspec-like pattern
49
40
  "**/__tests__/**", // jest pattern
41
+ "**/__test__/**", // jest pattern
50
42
  "**/__mocks__/**", // jest pattern
51
43
  "test.{js,jsx,ts,tsx}", // repos with a single test file
52
44
  "test-*.{js,jsx,ts,tsx}", // repos with multiple top-level test files
@@ -81,10 +73,6 @@ const rules = {
81
73
  // disallow AMD require/define
82
74
  // https://github.com/un-ts/eslint-plugin-import-x/blob/master/docs/rules/no-amd.md
83
75
  "import-x/no-amd": "error",
84
- // No Node.js builtin modules
85
- // https://github.com/un-ts/eslint-plugin-import-x/blob/master/docs/rules/no-nodejs-modules.md
86
- // TODO: enable?
87
- "import-x/no-nodejs-modules": "off",
88
76
  /* -------------------------------------------------------------------------- */
89
77
  /* Style guide: */
90
78
  /* -------------------------------------------------------------------------- */
@@ -110,15 +98,12 @@ const rules = {
110
98
  // Require a newline after the last import-x/require in a group
111
99
  // https://github.com/un-ts/eslint-plugin-import-x/blob/master/docs/rules/newline-after-import.md
112
100
  "import-x/newline-after-import": "error",
113
- // Require modules with a single export to use a default export
114
- // https://github.com/un-ts/eslint-plugin-import-x/blob/master/docs/rules/prefer-default-export.md
115
- "import-x/prefer-default-export": "off",
116
101
  // Forbid import of modules using absolute paths
117
102
  // https://github.com/un-ts/eslint-plugin-import-x/blob/master/docs/rules/no-absolute-path.md
118
103
  "import-x/no-absolute-path": "error",
119
104
  // Forbid require() calls with expressions
120
105
  // https://github.com/un-ts/eslint-plugin-import-x/blob/master/docs/rules/no-dynamic-require.md
121
- "import-x/no-dynamic-require": "error",
106
+ "import-x/no-dynamic-require": "warn",
122
107
  // Forbid Webpack loader syntax in imports
123
108
  // https://github.com/un-ts/eslint-plugin-import-x/blob/master/docs/rules/no-webpack-loader-syntax.md
124
109
  "import-x/no-webpack-loader-syntax": "error",
@@ -134,9 +119,6 @@ const rules = {
134
119
  // Ensures that there are no useless path segments
135
120
  // https://github.com/un-ts/eslint-plugin-import-x/blob/master/docs/rules/no-useless-path-segments.md
136
121
  "import-x/no-useless-path-segments": ["error", { commonjs: true }],
137
- // Reports modules without any exports, or with unused exports
138
- // https://github.com/un-ts/eslint-plugin-import-x/blob/master/docs/rules/no-unused-modules.md
139
- "import-x/no-unused-modules": "error",
140
122
  // Reports the use of import declarations with CommonJS exports in any module except for the main module.
141
123
  // https://github.com/un-ts/eslint-plugin-import-x/blob/master/docs/rules/no-import-module-exports.md
142
124
  "import-x/no-import-module-exports": [
@@ -146,16 +128,8 @@ const rules = {
146
128
  },
147
129
  ],
148
130
  // Use this rule to prevent importing packages through relative paths.
149
- // https://github.com/un-ts/eslint-plugin-import-x/blob/master/docs/rules/no-relative-packages-exports.md
131
+ // https://github.com/un-ts/eslint-plugin-import-x/blob/master/docs/rules/no-relative-packages.md
150
132
  "import-x/no-relative-packages": "error",
151
- // This seems conflicting with @typescript-eslint/no-import-type-side-effects
152
- // enforce a consistent style for type specifiers (inline or top-level)
153
- // https://github.com/un-ts/eslint-plugin-import-x/blob/master/docs/rules/consistent-type-specifier-style.md
154
- "import-x/consistent-type-specifier-style": "off",
155
- // Makes importing runtime (`import type {} from ...`) types annoying
156
- // Reports the use of empty named import blocks.
157
- // https://github.com/un-ts/eslint-plugin-import-x/blob/master/docs/rules/no-empty-named-blocks.md
158
- "import-x/no-empty-named-blocks": "off",
159
133
  };
160
134
 
161
135
  export default rules;
@@ -1,7 +1,7 @@
1
1
  // @ts-check
2
2
 
3
3
  /**
4
- * @satisfies {import("../../types/index.js").ESLintFlatConfig["rules"]}
4
+ * @satisfies {import("../../../types/index.js").ESLintFlatConfig["rules"]}
5
5
  */
6
6
  const rules = {
7
7
  // TODO use eslint-plugin-n https://github.com/eslint-community/eslint-plugin-n
@@ -0,0 +1,22 @@
1
+ // @ts-check
2
+
3
+ /**
4
+ * This file contains rules related to react. It is meant to be extended by react specific configs,
5
+ * it is not meant to be used directly.
6
+ * We are using @eslint-react/eslint-plugin for react specific rules, but we are not extending their
7
+ * recommended config as it includes some rules that we do not want to enforce, and it does not include
8
+ * some rules that we do want to enforce. We are only using the rules that we find useful and relevant
9
+ * for our projects.
10
+ * For more information on the available rules and their options, please refer to the documentation of
11
+ * @eslint-react/eslint-plugin and @eslint-react/eslint-plugin-hooks:
12
+ * https://beta.eslint-react.xyz/docs/rules/overview
13
+ */
14
+
15
+ /**
16
+ * @satisfies {import("../../../types/index.js").ESLintFlatConfig["rules"]}
17
+ */
18
+ const rules = {
19
+ // Add or modify react specific rules here if needed - use https://beta.eslint-react.xyz/docs/rules/overview for reference
20
+ };
21
+
22
+ export default rules;
@@ -0,0 +1,45 @@
1
+ // @ts-check
2
+ import eslintCoreRules from "./eslint-core.js";
3
+
4
+ /**
5
+ * @satisfies {import("../../../types/index.js").ESLintFlatConfig["rules"]}
6
+ *
7
+ * typesscript-eslint core recommended config https://github.com/typescript-eslint/typescript-eslint/blob/main/packages/eslint-plugin/src/configs/eslintrc/recommended-type-checked.ts
8
+ */
9
+ const rules = {
10
+ // modify/add rules from typescript-eslint package here additionally to the recommended rules
11
+
12
+ // turn off core rules superseded by @typescript-eslint equivalents
13
+ // shadows from outer scopes are not allowed
14
+ // https://typescript-eslint.io/rules/no-shadow
15
+ "no-shadow": "off",
16
+ "@typescript-eslint/no-shadow": eslintCoreRules["no-shadow"],
17
+
18
+ // Replace camelcase' rule with '@typescript-eslint/naming-convention'
19
+ // https://typescript-eslint.io/rules/naming-convention/
20
+ camelcase: "off",
21
+ // The `@typescript-eslint/naming-convention` rule allows `leadingUnderscore` and `trailingUnderscore` settings. However, the existing `no-underscore-dangle` rule already takes care of this.
22
+ "@typescript-eslint/naming-convention": [
23
+ "error",
24
+ // Allow camelCase variables (23.2), PascalCase variables (23.8), and UPPER_CASE variables (23.10)
25
+ {
26
+ selector: "variable",
27
+ format: ["camelCase", "PascalCase", "UPPER_CASE"],
28
+ },
29
+ // Allow camelCase functions (23.2), and PascalCase functions (23.8)
30
+ {
31
+ selector: "function",
32
+ format: ["camelCase", "PascalCase"],
33
+ },
34
+ // Qlik recommends PascalCase for classes (23.3),
35
+ {
36
+ selector: "typeLike",
37
+ format: ["PascalCase"],
38
+ },
39
+ ],
40
+
41
+ // use tsconfig's noImplicitReturns option rather than this rule
42
+ "consistent-return": "off",
43
+ };
44
+
45
+ export default rules;
@@ -1,20 +1,35 @@
1
1
  // @ts-check
2
2
  import globals from "globals";
3
3
  import { mergeConfigs } from "../../utils/config.js";
4
- import nodeRules from "../rules/node.js";
5
4
  import { baseConfigJS, baseConfigTS } from "./base.js";
5
+ import nodeRules from "./default-rules/node.js";
6
+
7
+ // TODO use eslint-plugin-n https://github.com/eslint-community/eslint-plugin-n
6
8
 
7
9
  /**
8
- * @satisfies {import("../../types/index.js").ESLintFlatConfig['rules']}
10
+ * @satisfies {import("../../types/index.js").ESLintFlatConfig["rules"]}
9
11
  */
10
- const cjsRules = {
12
+ const nodeEsmRules = {
11
13
  ...nodeRules,
12
- // modify rules for node commonjs here
14
+ // modify rules for node esm here
15
+
16
+ // Ensure consistent use of file extension within the import path
17
+ // https://github.com/un-ts/eslint-plugin-import-x/blob/master/docs/rules/extensions.md
18
+ "import-x/extensions": [
19
+ "error",
20
+ "ignorePackages",
21
+ {
22
+ ts: "never",
23
+ mts: "never",
24
+ tsx: "never",
25
+ },
26
+ ],
13
27
  };
14
28
 
15
29
  /**
16
30
  * CJS config for javascript in node
17
31
  * @type {import("../../types/index.js").ESLintFlatConfig}
32
+ * This config is meant to be extended by javascript specific configs, it is not meant to be used directly.
18
33
  */
19
34
  const baseCjsJS = mergeConfigs(
20
35
  // base it on the recommended javascript config
@@ -25,12 +40,16 @@ const baseCjsJS = mergeConfigs(
25
40
  globals: globals.node,
26
41
  sourceType: "commonjs",
27
42
  },
28
- rules: cjsRules,
43
+ rules: {
44
+ ...nodeRules,
45
+ // modify javascript specific rules for node cjs here if needed
46
+ },
29
47
  },
30
48
  );
31
49
 
32
50
  /**
33
51
  * CJS config for typescript in node
52
+ * This config is meant to be extended by typescript specific configs, it is not meant to be used directly.
34
53
  * @type {import("../../types/index.js").ESLintFlatConfig}
35
54
  */
36
55
  const baseCjsTS = mergeConfigs(
@@ -43,32 +62,12 @@ const baseCjsTS = mergeConfigs(
43
62
  sourceType: "commonjs",
44
63
  },
45
64
  rules: {
46
- ...cjsRules,
47
- // modify ts specific rules for node here
65
+ ...nodeRules,
66
+ // modify typescript specific rules for node cjs here if needed
48
67
  },
49
68
  },
50
69
  );
51
70
 
52
- /**
53
- * @satisfies {import("../../types/index.js").ESLintFlatConfig["rules"]}
54
- */
55
- const nodeEsmRules = {
56
- ...nodeRules,
57
- // modify rules for node esm here
58
-
59
- // Ensure consistent use of file extension within the import path
60
- // https://github.com/un-ts/eslint-plugin-import-x/blob/master/docs/rules/extensions.md
61
- "import-x/extensions": [
62
- "error",
63
- "ignorePackages",
64
- {
65
- ts: "never",
66
- mts: "never",
67
- tsx: "never",
68
- },
69
- ],
70
- };
71
-
72
71
  /**
73
72
  * ESM config for javascript in node
74
73
  * @type {import("../../types/index.js").ESLintFlatConfig}
@@ -82,7 +81,11 @@ const baseEsmJS = mergeConfigs(
82
81
  globals: globals.node,
83
82
  sourceType: "module",
84
83
  },
85
- rules: nodeEsmRules,
84
+ rules: {
85
+ ...nodeRules,
86
+ ...nodeEsmRules,
87
+ // modify javascript specific rules for node esm here if needed
88
+ },
86
89
  },
87
90
  );
88
91
 
@@ -100,6 +103,7 @@ const baseEsmTS = mergeConfigs(
100
103
  sourceType: "module",
101
104
  },
102
105
  rules: {
106
+ ...nodeRules,
103
107
  ...nodeEsmRules,
104
108
  // modify typescript specific rules for node esm here if needed
105
109
  },
@@ -5,7 +5,7 @@ import { mergeConfigs } from "../utils/config.js";
5
5
 
6
6
  /**
7
7
  * @type {import("../types/index.js").ESLintFlatConfig}
8
- * config for jest https://github.com/jest-community/eslint-plugin-jest
8
+ * config for vitest https://github.com/vitest/eslint-plugin-vitest
9
9
  */
10
10
  const vitest = mergeConfigs(
11
11
  // base it on the recommended vitest config
@@ -23,4 +23,3 @@ const vitest = mergeConfigs(
23
23
  );
24
24
 
25
25
  export default [vitest];
26
- export { vitest };
package/src/index.d.ts CHANGED
@@ -1,40 +1,20 @@
1
1
  import cjs, { cjsJS, cjsTS } from "./configs/cjs.js";
2
2
  import esbrowser, { esbrowserJS, esbrowserTS } from "./configs/esbrowser.js";
3
3
  import esm, { esmJS, esmTS } from "./configs/esm.js";
4
- import jest from "./configs/jest.js";
5
- import playwright from "./configs/playwright.js";
6
4
  import react, { reactJS, reactTS } from "./configs/react.js";
7
5
  import recommended, { recommendedJS, recommendedTS } from "./configs/recommended.js";
8
- import svelte, { svelteJS } from "./configs/svelte.js";
9
6
  import vitest from "./configs/vitest.js";
10
- import compose from "./utils/compose.js";
11
7
 
12
8
  declare namespace qlikEslintConfig {
13
9
  export namespace configs {
14
10
  export { cjs };
15
11
  export { esbrowser };
16
12
  export { esm };
17
- export { playwright };
18
- export { jest };
19
13
  export { react };
20
14
  export { recommended };
21
- export { svelte };
22
15
  export { vitest };
23
16
  }
24
- export { compose };
25
17
  }
26
18
 
27
19
  export default qlikEslintConfig;
28
- export {
29
- cjsJS,
30
- cjsTS,
31
- esbrowserJS,
32
- esbrowserTS,
33
- esmJS,
34
- esmTS,
35
- reactJS,
36
- reactTS,
37
- recommendedJS,
38
- recommendedTS,
39
- svelteJS,
40
- };
20
+ export { cjsJS, cjsTS, esbrowserJS, esbrowserTS, esmJS, esmTS, reactJS, reactTS, recommendedJS, recommendedTS };
package/src/index.js CHANGED
@@ -2,13 +2,9 @@
2
2
  import cjs, { cjsJS, cjsTS } from "./configs/cjs.js";
3
3
  import esbrowser, { esbrowserJS, esbrowserTS } from "./configs/esbrowser.js";
4
4
  import esm, { esmJS, esmTS } from "./configs/esm.js";
5
- import jest from "./configs/jest.js";
6
- import playwright from "./configs/playwright.js";
7
5
  import react, { reactJS, reactTS } from "./configs/react.js";
8
6
  import recommended, { recommendedJS, recommendedTS } from "./configs/recommended.js";
9
- import svelte, { svelteJS } from "./configs/svelte.js";
10
7
  import vitest from "./configs/vitest.js";
11
- import compose from "./utils/compose.js";
12
8
 
13
9
  /**
14
10
  * @satisfies {import("./types/index.js").QlikEslintConfig}
@@ -18,28 +14,12 @@ const qlikEslintConfig = {
18
14
  cjs,
19
15
  esbrowser,
20
16
  esm,
21
- jest,
22
- playwright,
23
17
  react,
24
18
  recommended,
25
- svelte,
26
19
  vitest,
27
20
  },
28
- compose,
29
21
  };
30
22
 
31
23
  export default qlikEslintConfig;
32
24
 
33
- export {
34
- cjsJS,
35
- cjsTS,
36
- esbrowserJS,
37
- esbrowserTS,
38
- esmJS,
39
- esmTS,
40
- reactJS,
41
- reactTS,
42
- recommendedJS,
43
- recommendedTS,
44
- svelteJS,
45
- };
25
+ export { cjsJS, cjsTS, esbrowserJS, esbrowserTS, esmJS, esmTS, reactJS, reactTS, recommendedJS, recommendedTS };
@@ -1,52 +1,11 @@
1
- /* eslint-disable @typescript-eslint/no-empty-object-type */
2
- import { TSESLint } from "@typescript-eslint/utils";
1
+ import type { Linter } from "eslint";
3
2
 
4
- interface ESLintFlatConfig extends TSESLint.FlatConfig.Config {}
5
- interface ESLintPlugin extends TSESLint.FlatConfig.Plugin {}
6
- interface ESLintLanguageOptions extends TSESLint.FlatConfig.LanguageOptions {}
7
-
8
- interface ESLintFlatConfigWithExtend extends ESLintFlatConfig {
9
- /**
10
- * Allows you to "extend" a set of configs similar to `extends` from the
11
- * classic configs.
12
- *
13
- * This is just a convenience short-hand to help reduce duplication.
14
- *
15
- * ```js
16
- * export default qlikEslint.compose({
17
- * files: ['** /*.ts'],
18
- * extend: [
19
- * ...qlikEslint.configs.ts,
20
- * ],
21
- * rules: {
22
- * '@typescript-eslint/array-type': 'error',
23
- * '@typescript-eslint/consistent-type-imports': 'error',
24
- * },
25
- * })
26
- *
27
- * // expands to
28
- *
29
- * export default [
30
- * ...qlikEslint.configs.ts.map(conf => ({
31
- * ...conf,
32
- * files: ['** /*.ts'],
33
- * })),
34
- * {
35
- * files: ['** /*.ts'],
36
- * rules: {
37
- * '@typescript-eslint/array-type': 'error',
38
- * '@typescript-eslint/consistent-type-imports': 'error',
39
- * },
40
- * },
41
- * ]
42
- * ```
43
- */
44
- extend?: ESLintFlatConfig[];
45
- }
3
+ type ESLintFlatConfig = Linter.Config;
4
+ type ESLintPlugin = NonNullable<Linter.Config["plugins"]>[string];
5
+ type ESLintLanguageOptions = NonNullable<Linter.Config["languageOptions"]>;
46
6
 
47
7
  type QlikEslintConfig = {
48
8
  configs: Record<string, ESLintFlatConfig[]>;
49
- compose: (...configs: ESLintFlatConfigWithExtend[]) => ESLintFlatConfig[];
50
9
  };
51
10
 
52
- export type { ESLintFlatConfig, ESLintFlatConfigWithExtend, ESLintLanguageOptions, ESLintPlugin, QlikEslintConfig };
11
+ export type { ESLintFlatConfig, ESLintLanguageOptions, ESLintPlugin, QlikEslintConfig };
@@ -1,4 +1,3 @@
1
- import tsEslint from "typescript-eslint";
2
1
  import { merge } from "./merge.js";
3
2
 
4
3
  /**
@@ -18,5 +17,3 @@ export function mergeConfigs(...configs) {
18
17
  }
19
18
  return mergedConfig;
20
19
  }
21
-
22
- export const config = tsEslint.config;
@@ -3,10 +3,10 @@ const noNeedToDeepMerge = ["plugins", "rules", "parser"];
3
3
  const overWrite = ["files", "globals", "ignores"];
4
4
 
5
5
  /**
6
- *
6
+ * Deep merge two objects, with special handling for certain keys
7
7
  * @param {any} obj1
8
8
  * @param {any} obj2
9
- * @returns
9
+ * @returns {object}
10
10
  */
11
11
  export const merge = (obj1, obj2) => {
12
12
  // add error handling
@@ -1,27 +0,0 @@
1
- // @ts-check
2
- import jestPlugin from "eslint-plugin-jest";
3
- import testingLibraryPlugin from "eslint-plugin-testing-library";
4
- import { mergeConfigs } from "../utils/config.js";
5
-
6
- /**
7
- * @type {import("../types/index.js").ESLintFlatConfig}
8
- * config for jest https://github.com/jest-community/eslint-plugin-jest
9
- */
10
- const jest = mergeConfigs(
11
- // base it on the recommended jest config
12
- jestPlugin.configs["flat/recommended"],
13
- // add testing-library plugin recommended config for react
14
- testingLibraryPlugin.configs["flat/react"],
15
- // add qlik's recommended jest config
16
- {
17
- name: "jest",
18
- files: ["**/__test__/**/*.{js,jsx,ts,tsx}", "**/__tests__/**/*.{js,jsx,ts,tsx}"],
19
- rules: {
20
- // ...testingLibraryRules,
21
- // modify rules from eslint-plugin-jest here
22
- },
23
- },
24
- );
25
-
26
- export default [jest];
27
- export { jest };
@@ -1,24 +0,0 @@
1
- // @ts-check
2
- import playwrightEslint from "eslint-plugin-playwright";
3
- import { mergeConfigs } from "../utils/config.js";
4
-
5
- /**
6
- * @type {import("../types/index.js").ESLintFlatConfig}
7
- * config for Playwright https://github.com/playwright-community/eslint-plugin-playwright
8
- */
9
- const playwright = mergeConfigs(
10
- // base it on the recommended config
11
- playwrightEslint.configs["flat/recommended"],
12
- // add qlik's recommended playwright config
13
- {
14
- name: "playwright",
15
- files: ["tests/**", "test/**"],
16
- rules: {
17
- ...playwrightEslint.configs["flat/recommended"].rules,
18
- // modify rules from eslint-plugin-playwright here
19
- },
20
- },
21
- );
22
-
23
- export default [playwright];
24
- export { playwright };