@prowise/eslint-config-linting-rules 2.0.0 → 2.0.2

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.
@@ -72,13 +72,6 @@ const rules = {
72
72
  */
73
73
  "no-disabled-tests": "warn",
74
74
 
75
- /**
76
- * Disallow using a callback in asynchronous tests and hooks ✅
77
- * Jest: https://github.com/jest-community/eslint-plugin-jest/blob/main/docs/rules/no-done-callback.md
78
- * Vitest: https://github.com/veritem/eslint-plugin-vitest/blob/main/docs/rules/no-done-callback.md
79
- */
80
- "no-done-callback": "warn",
81
-
82
75
  /**
83
76
  * Disallow duplicate setup and teardown hooks
84
77
  * Jest: https://github.com/jest-community/eslint-plugin-jest/blob/main/docs/rules/no-duplicate-hooks.md
@@ -329,111 +322,10 @@ const rules = {
329
322
  * @param framework Used test framework
330
323
  * @returns Testing rules.
331
324
  */
332
- function commonRules(framework) {
325
+ export function commonRules(framework) {
333
326
  const updated = {};
334
327
  for (const key in rules) {
335
328
  updated[`${framework}/${key}`] = rules[key];
336
329
  }
337
330
  return updated;
338
331
  }
339
-
340
- module.exports = {
341
- jestRules: {
342
- ...commonRules("jest"),
343
-
344
- /**
345
- * Disallow confusing usages of jest.setTimeout
346
- * https://github.com/jest-community/eslint-plugin-jest/blob/main/docs/rules/no-confusing-set-timeout.md
347
- */
348
- "jest/no-confusing-set-timeout": "off",
349
-
350
- /**
351
- * Disallow use of deprecated functions ✅ 🔧
352
- * https://github.com/jest-community/eslint-plugin-jest/blob/main/docs/rules/no-deprecated-functions.md
353
- */
354
- "jest/no-deprecated-functions": "error",
355
-
356
- /**
357
- * Disallow using exports in files containing tests ✅
358
- * https://github.com/jest-community/eslint-plugin-jest/blob/main/docs/rules/no-export.md
359
- */
360
- "jest/no-export": "error",
361
-
362
- /**
363
- * Disallow Jasmine globals ✅ 🔧
364
- * https://github.com/jest-community/eslint-plugin-jest/blob/main/docs/rules/no-jasmine-globals.md
365
- */
366
- "jest/no-jasmine-globals": "error",
367
-
368
- /**
369
- * Disallow specific jest. methods
370
- * https://github.com/jest-community/eslint-plugin-jest/blob/main/docs/rules/no-restricted-jest-methods.md
371
- */
372
- "jest/no-restricted-jest-methods": "off",
373
-
374
- /**
375
- * Disallow using jest.mock() factories without an explicit type parameter
376
- * https://github.com/jest-community/eslint-plugin-jest/blob/main/docs/rules/no-untyped-mock-factory.md
377
- */
378
- "jest/no-untyped-mock-factory": "off",
379
-
380
- /**
381
- * Require promises that have expectations in their chain to be valid ✅
382
- * https://github.com/jest-community/eslint-plugin-jest/blob/main/docs/rules/valid-expect-in-promise.md
383
- */
384
- "jest/valid-expect-in-promise": "error",
385
-
386
- },
387
-
388
- vitestRules: {
389
- ...commonRules("vitest"),
390
-
391
- /**
392
- * Forbidden test file pattern: default only "test" accepted
393
- * https://github.com/veritem/eslint-plugin-vitest/blob/main/docs/rules/consistent-test-filename.md
394
- */
395
- "vitest/consistent-test-filename": ["off", { pattern: ".*\\.test\\.[tj]sx?$" }],
396
-
397
- /**
398
- * Do not use conditionals to run tests
399
- * https://github.com/veritem/eslint-plugin-vitest/blob/main/docs/rules/no-conditional-tests.md
400
- */
401
- "vitest/no-conditional-tests": "off",
402
-
403
- /**
404
- * Disallow importing node:test ✅ 🔧
405
- * https://github.com/veritem/eslint-plugin-vitest/blob/main/docs/rules/no-import-node-test.md
406
- */
407
- "vitest/no-import-node-test": "error",
408
-
409
- /**
410
- * Disallow specific vi. methods
411
- * https://github.com/veritem/eslint-plugin-vitest/blob/main/docs/rules/no-restricted-vi-methods.md
412
- */
413
- "vitest/no-restricted-vi-methods": "off",
414
-
415
- /**
416
- * Suggest using toBeFalsy() 🔧
417
- * https://github.com/veritem/eslint-plugin-vitest/blob/main/docs/rules/prefer-to-be-falsy.md
418
- */
419
- "vitest/prefer-to-be-falsy)": "off",
420
-
421
- /**
422
- * Prefer toBeObject() 🔧
423
- * https://github.com/veritem/eslint-plugin-vitest/blob/main/docs/rules/prefer-to-be-object.md
424
- */
425
- "vitest/prefer-to-be-object": "off",
426
-
427
- /**
428
- * Suggest using toBeTruthy 🔧
429
- * https://github.com/veritem/eslint-plugin-vitest/blob/main/docs/rules/prefer-to-be-truthy.md
430
- */
431
- "vitest/prefer-to-be-truthy": "off",
432
-
433
- /**
434
- * Require local Test Context for concurrent snapshot tests ✅
435
- * https://github.com/veritem/eslint-plugin-vitest/blob/main/docs/rules/require-local-test-context-for-concurrent-snapshots.md
436
- */
437
- "vitest/require-local-test-context-for-concurrent-snapshots": "error",
438
- },
439
- };
package/typescript.js CHANGED
@@ -1,23 +1,7 @@
1
- /**
2
- *
3
- */
4
- const { rules: tsRules } = require("./rules/plugin-typescript-rules");
1
+ /*
2
+ * Default rules for all typescript projects
3
+ */
4
+ import base from "./base.js";
5
+ import typescript from "./rules/plugin-typescript-rules.js";
5
6
 
6
- module.exports = {
7
- extends: ["./index.js"].map(require.resolve),
8
-
9
- plugins: ["@typescript-eslint"],
10
-
11
- parser: "@typescript-eslint/parser",
12
- rules: { ...tsRules },
13
-
14
- settings: {
15
- "import/parsers": { "@typescript-eslint/parser": [".ts", ".tsx"] },
16
- "import/resolver": {
17
- typescript: {
18
- alwaysTryTypes: true,
19
- project: __dirname, // use tsconfig.json of the root folder (where esLint is running from)
20
- },
21
- },
22
- },
23
- };
7
+ export default [base, typescript];
@@ -1,155 +0,0 @@
1
- /* eslint-disable prefer-arrow/prefer-arrow-functions */
2
- const { default: moduleVisitor } = require("eslint-module-utils/moduleVisitor");
3
- const { default: resolve } = require("eslint-module-utils/resolve");
4
- const { isBuiltIn } = require("eslint-plugin-import/lib/core/importType");
5
- const fs = require("fs");
6
- const JSON5 = require("json5");
7
- const path = require("path");
8
-
9
- /**
10
- * Map correct extension
11
- *
12
- * @param extension Extension to map.
13
- * @returns Correct extension.
14
- */
15
- function mapExtension(extension) {
16
- switch (extension) {
17
- case ".ts":
18
- return ".js";
19
- case ".tsx":
20
- return ".jsx";
21
- case ".cts":
22
- return ".cjs";
23
- default:
24
- return extension;
25
- }
26
- }
27
-
28
- /**
29
- * Return the root path.
30
- *
31
- * @param context Context
32
- * @returns Root path.
33
- */
34
- function getRootCwd(context) {
35
- const cwd = context.cwd || process.cwd();
36
- if (
37
- !context.parserOptions.project ||
38
- !fs.existsSync(context.parserOptions.project)
39
- ) {
40
- return cwd;
41
- }
42
-
43
- const data = JSON5.parse(fs.readFileSync(context.parserOptions.project));
44
- if (!data?.compilerOptions?.baseUrl) {
45
- return cwd;
46
- }
47
- return path.join(path.dirname(context.parserOptions.project), data.compilerOptions.baseUrl);
48
- }
49
-
50
- module.exports = {
51
- rules: {
52
- "force-extensions": {
53
- meta: {
54
- type: "suggestion",
55
- docs: {
56
- category: "Style guide",
57
- description: "Ensure consistent use of file extension within the import path.",
58
- },
59
- fixable: "code",
60
- },
61
- schema: [],
62
-
63
- // eslint-disable-next-line jsdoc/require-jsdoc
64
- create(context) {
65
- const cwd = getRootCwd(context);
66
- const nodeModulesTypesPath = path.join(cwd, "node_modules", "@types");
67
- const nodeModulesPath = path.join(cwd, "node_modules");
68
-
69
- // eslint-disable-next-line jsdoc/require-jsdoc
70
- function isExternalType(resolvedPath) {
71
- return !path.relative(nodeModulesTypesPath, resolvedPath).startsWith("..");
72
- }
73
-
74
- // eslint-disable-next-line jsdoc/require-jsdoc
75
- function isExternal(resolvedPath) {
76
- return !path.relative(nodeModulesPath, resolvedPath).startsWith("..");
77
- }
78
-
79
- // eslint-disable-next-line jsdoc/require-jsdoc
80
- function isIndex(checkPath) {
81
- return path.parse(checkPath).name === "index";
82
- }
83
-
84
- // eslint-disable-next-line jsdoc/require-jsdoc
85
- function resolveAndMap(importPath) {
86
- const resolvedPath = resolve(importPath, context) || importPath;
87
- if (!resolvedPath) {
88
- return undefined;
89
- }
90
- const parsed = path.parse(resolvedPath);
91
- return path.join(parsed.dir, `${parsed.name.replace(/\.d/, "")}${mapExtension(parsed.ext)}`);
92
- }
93
-
94
- // eslint-disable-next-line jsdoc/require-jsdoc
95
- function checkFileExtension(source, node) {
96
- // bail if the declaration doesn't have a source, e.g. "export { foo };",
97
- // or if it's only partially typed like in an editor
98
- if (!source || !source.value) { return; }
99
- // don't enforce anything on builtins
100
- if (isBuiltIn(source.value, context.settings)) {
101
- return;
102
- }
103
-
104
- const importPath = source.value.replace(/\?(.*)$/, "");
105
- const resolvedPath = resolveAndMap(source.value, context);
106
-
107
- const resolvedExtension = path.extname(resolvedPath).substring(1);
108
- const importExtension = path.extname(node.source.value).substring(1);
109
-
110
- if (resolvedExtension === importExtension) {
111
- return;
112
- }
113
-
114
- if (isExternal(resolvedPath)) {
115
- if (!importPath.startsWith("@prowise/")) {
116
- // TODO figure out all te import rules for packages
117
- // We need to read exports in package.json
118
- // There might be a better way?
119
- return;
120
- }
121
- if (fs.existsSync(path.join(
122
- isExternalType(resolvedPath) ? nodeModulesTypesPath : nodeModulesPath,
123
- importPath,
124
- "package.json",
125
- ))) {
126
- return;
127
- }
128
- }
129
-
130
- if (isIndex(resolvedPath) && !isIndex(path.basename(importPath))) {
131
- context.report({
132
- node: source,
133
- message: `Missing index.${resolvedExtension} for import "${importPath}"`,
134
- fix: (fixer) => {
135
- const fixValue = `${importPath}/index.${resolvedExtension}`;
136
- return fixer.replaceText(node.source, `"${node.source.value.replace(importPath, fixValue)}"`);
137
- },
138
- });
139
- return;
140
- }
141
-
142
- context.report({
143
- node: source,
144
- message: `${importExtension ? `Incorrect extension "${importExtension}"` : "Missing extension"} for import: "${node.source.value}"`,
145
- fix: (fixer) => {
146
- const fixValue = `${importPath.substring(0, importPath.length - (importExtension.length ? importExtension.length + 1 : 0))}.${resolvedExtension}`;
147
- return fixer.replaceText(node.source, `"${node.source.value.replace(importPath, fixValue)}"`);
148
- },
149
- });
150
- }
151
- return moduleVisitor(checkFileExtension, { commonjs: true });
152
- },
153
- },
154
- },
155
- };
@@ -1,21 +0,0 @@
1
- {
2
- "name": "eslint-plugin-esm-extensions",
3
- "version": "1.0.0",
4
- "scripts": {},
5
- "main": "./index.js",
6
- "type": "commonjs",
7
- "exports": {
8
- "require": "./index.js"
9
- },
10
- "files": [
11
- "index.js"
12
- ],
13
- "dependencies": {
14
- "eslint-module-utils": ">=2",
15
- "eslint-plugin-import": ">=2",
16
- "json5": ">=1"
17
- },
18
- "peerDependencies": {
19
- "eslint": ">=8"
20
- }
21
- }
package/frontend-vite.js DELETED
@@ -1,38 +0,0 @@
1
- const { rules: reactHooksRules } = require("./rules/plugin-react-hooks-rules");
2
- const { rules: reactRules } = require("./rules/plugin-react-rules");
3
- const { vitestRules } = require("./rules/test-rules");
4
-
5
- module.exports = {
6
- extends: ["./typescript.js"].map(require.resolve),
7
-
8
- env: {
9
- browser: true,
10
- },
11
-
12
- settings: {
13
- react: {
14
- version: "detect",
15
- },
16
- },
17
-
18
- globals: {
19
- Atomics: "readonly",
20
- SharedArrayBuffer: "readonly",
21
- },
22
-
23
- parserOptions: {
24
- ecmaFeatures: { jsx: true },
25
- },
26
-
27
- plugins: [
28
- "eslint-plugin-react",
29
- "eslint-plugin-react-hooks",
30
- "eslint-plugin-vitest",
31
- ],
32
-
33
- rules: {
34
- ...reactRules,
35
- ...reactHooksRules,
36
- ...vitestRules,
37
- },
38
- };
package/frontend.js DELETED
@@ -1,39 +0,0 @@
1
- const { rules: reactHooksRules } = require("./rules/plugin-react-hooks-rules");
2
- const { rules: reactRules } = require("./rules/plugin-react-rules");
3
- const { jestRules } = require("./rules/test-rules");
4
-
5
- module.exports = {
6
- extends: ["./typescript.js"].map(require.resolve),
7
-
8
- env: {
9
- jest: true,
10
- browser: true,
11
- },
12
-
13
- settings: {
14
- react: {
15
- version: "detect",
16
- },
17
- },
18
-
19
- globals: {
20
- Atomics: "readonly",
21
- SharedArrayBuffer: "readonly",
22
- },
23
-
24
- parserOptions: {
25
- ecmaFeatures: { jsx: true },
26
- },
27
-
28
- plugins: [
29
- "eslint-plugin-react",
30
- "eslint-plugin-react-hooks",
31
- "eslint-plugin-jest",
32
- ],
33
-
34
- rules: {
35
- ...reactRules,
36
- ...reactHooksRules,
37
- ...jestRules,
38
- },
39
- };
package/solid.js DELETED
@@ -1,35 +0,0 @@
1
- const { rules: solidRules } = require("./rules/plugin-solid-rules");
2
- const { vitestRules } = require("./rules/test-rules");
3
-
4
- module.exports = {
5
- extends: ["./typescript.js"].map(require.resolve),
6
-
7
- env: { browser: true },
8
- globals: {
9
- suite: true,
10
- test: true,
11
- describe: true,
12
- it: true,
13
- expectTypeOf: true,
14
- assertType: true,
15
- expect: true,
16
- assert: true,
17
- vitest: true,
18
- vi: true,
19
- beforeAll: true,
20
- afterAll: true,
21
- beforeEach: true,
22
- afterEach: true,
23
- },
24
-
25
- plugins: [
26
- "eslint-plugin-solid",
27
- "vitest",
28
- ],
29
-
30
- parserOptions: {
31
- ecmaFeatures: { jsx: true },
32
- },
33
-
34
- rules: { ...solidRules, ...vitestRules },
35
- };