@prowise/eslint-config-linting-rules 1.2.13 → 2.0.1

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.
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/index.js DELETED
@@ -1,35 +0,0 @@
1
- const { rules: baseRules } = require("./rules/base-rules");
2
- const { rules: importsRules } = require("./rules/plugin-import-rules");
3
- const { rules: jsDocRules } = require("./rules/plugin-jsdoc-rules");
4
-
5
- module.exports = {
6
- env: {
7
- es2024: true,
8
- },
9
-
10
- plugins: [
11
- "eslint-plugin-import",
12
- "eslint-plugin-prefer-arrow",
13
- "eslint-plugin-jsdoc",
14
- ],
15
-
16
- parserOptions: {
17
- ecmaVersion: "latest",
18
- sourceType: "module",
19
- },
20
-
21
- rules: {
22
- ...baseRules,
23
- ...importsRules,
24
- ...jsDocRules,
25
- "prefer-arrow/prefer-arrow-functions": [
26
- "warn",
27
- {
28
- disallowPrototype: true,
29
- singleReturnOnly: false,
30
- classPropertiesAllowed: false,
31
- allowStandaloneDeclarations: true,
32
- },
33
- ],
34
- },
35
- };
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
- };