@virmator/lint 14.21.3 → 14.23.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.
package/README.md CHANGED
@@ -14,10 +14,8 @@ A default plugin for [virmator](https://www.npmjs.com/package/virmator).
14
14
  - eslint.config.ts
15
15
  - Deps
16
16
  - [eslint](https://npmjs.com/package/eslint)
17
- - [eslint-plugin-require-extensions](https://npmjs.com/package/eslint-plugin-require-extensions)
18
17
  - [eslint-plugin-unicorn](https://npmjs.com/package/eslint-plugin-unicorn)
19
18
  - [@eslint/js](https://npmjs.com/package/@eslint/js)
20
- - [@eslint/eslintrc](https://npmjs.com/package/@eslint/eslintrc)
21
19
  - [@stylistic/eslint-plugin](https://npmjs.com/package/@stylistic/eslint-plugin)
22
20
  - [@stylistic/eslint-plugin-ts](https://npmjs.com/package/@stylistic/eslint-plugin-ts)
23
21
  - [@typescript-eslint/eslint-plugin](https://npmjs.com/package/@typescript-eslint/eslint-plugin)
@@ -1,4 +1,3 @@
1
- import {FlatCompat} from '@eslint/eslintrc';
2
1
  import jsEslint from '@eslint/js';
3
2
  import stylistic from '@stylistic/eslint-plugin';
4
3
  import jsdoc from 'eslint-plugin-jsdoc';
@@ -11,6 +10,7 @@ import noRelativeImportOutsidePackageRule from '../src/rules/no-relative-import-
11
10
  import preferIfElseChainRule from '../src/rules/prefer-if-else-chain.lint.js';
12
11
  import preferParseUrlRule from '../src/rules/prefer-parse-url.lint.js';
13
12
  import preferSingleQuotesRule from '../src/rules/prefer-single-quotes.lint.js';
13
+ import requireImportExtensionsRule from '../src/rules/require-import-extensions.lint.js';
14
14
 
15
15
  export const globalVars = {
16
16
  ...globals.node,
@@ -18,13 +18,7 @@ export const globalVars = {
18
18
  };
19
19
 
20
20
  export function defineEslintConfig(repoDir: string) {
21
- const compat = new FlatCompat({
22
- baseDirectory: repoDir,
23
- });
24
-
25
21
  return [
26
- ...compat.plugins('require-extensions'),
27
- ...compat.extends('plugin:require-extensions/recommended'),
28
22
  {
29
23
  ignores: [
30
24
  '*.graphql',
@@ -70,6 +64,7 @@ export function defineEslintConfig(repoDir: string) {
70
64
  'prefer-if-else-chain': preferIfElseChainRule,
71
65
  'prefer-parse-url': preferParseUrlRule,
72
66
  'prefer-single-quotes': preferSingleQuotesRule,
67
+ 'require-import-extensions': requireImportExtensionsRule,
73
68
  },
74
69
  },
75
70
  },
@@ -175,6 +170,7 @@ export function defineEslintConfig(repoDir: string) {
175
170
  '@virmator/prefer-if-else-chain': 'error',
176
171
  '@virmator/prefer-parse-url': 'error',
177
172
  '@virmator/prefer-single-quotes': 'error',
173
+ '@virmator/require-import-extensions': 'error',
178
174
  'no-lonely-if': 'error',
179
175
  curly: 'error',
180
176
  'object-shorthand': 'error',
package/dist/lint.d.ts CHANGED
@@ -48,17 +48,6 @@ export declare const virmatorLintPlugin: Readonly<Readonly<{
48
48
  readonly "mono-root": true;
49
49
  };
50
50
  };
51
- readonly 'eslint-plugin-require-extensions': {
52
- readonly type: NpmDepType.Dev;
53
- readonly env: {
54
- readonly node: true;
55
- readonly web: true;
56
- };
57
- readonly packageType: {
58
- readonly package: true;
59
- readonly "mono-root": true;
60
- };
61
- };
62
51
  readonly 'eslint-plugin-unicorn': {
63
52
  readonly type: NpmDepType.Dev;
64
53
  readonly env: {
@@ -81,17 +70,6 @@ export declare const virmatorLintPlugin: Readonly<Readonly<{
81
70
  readonly "mono-root": true;
82
71
  };
83
72
  };
84
- readonly '@eslint/eslintrc': {
85
- readonly type: NpmDepType.Dev;
86
- readonly env: {
87
- readonly node: true;
88
- readonly web: true;
89
- };
90
- readonly packageType: {
91
- readonly package: true;
92
- readonly "mono-root": true;
93
- };
94
- };
95
73
  readonly '@stylistic/eslint-plugin': {
96
74
  readonly type: NpmDepType.Dev;
97
75
  readonly env: {
@@ -242,17 +220,6 @@ export declare const virmatorLintPlugin: Readonly<Readonly<{
242
220
  readonly "mono-root": true;
243
221
  };
244
222
  };
245
- readonly 'eslint-plugin-require-extensions': {
246
- readonly type: NpmDepType.Dev;
247
- readonly env: {
248
- readonly node: true;
249
- readonly web: true;
250
- };
251
- readonly packageType: {
252
- readonly package: true;
253
- readonly "mono-root": true;
254
- };
255
- };
256
223
  readonly 'eslint-plugin-unicorn': {
257
224
  readonly type: NpmDepType.Dev;
258
225
  readonly env: {
@@ -275,17 +242,6 @@ export declare const virmatorLintPlugin: Readonly<Readonly<{
275
242
  readonly "mono-root": true;
276
243
  };
277
244
  };
278
- readonly '@eslint/eslintrc': {
279
- readonly type: NpmDepType.Dev;
280
- readonly env: {
281
- readonly node: true;
282
- readonly web: true;
283
- };
284
- readonly packageType: {
285
- readonly package: true;
286
- readonly "mono-root": true;
287
- };
288
- };
289
245
  readonly '@stylistic/eslint-plugin': {
290
246
  readonly type: NpmDepType.Dev;
291
247
  readonly env: {
package/dist/lint.js CHANGED
@@ -68,17 +68,6 @@ export const virmatorLintPlugin = defineVirmatorPlugin(import.meta.dirname, {
68
68
  [PackageType.MonoRoot]: true,
69
69
  },
70
70
  },
71
- 'eslint-plugin-require-extensions': {
72
- type: NpmDepType.Dev,
73
- env: {
74
- [RuntimeEnv.Node]: true,
75
- [RuntimeEnv.Web]: true,
76
- },
77
- packageType: {
78
- [PackageType.TopPackage]: true,
79
- [PackageType.MonoRoot]: true,
80
- },
81
- },
82
71
  'eslint-plugin-unicorn': {
83
72
  type: NpmDepType.Dev,
84
73
  env: {
@@ -101,17 +90,6 @@ export const virmatorLintPlugin = defineVirmatorPlugin(import.meta.dirname, {
101
90
  [PackageType.MonoRoot]: true,
102
91
  },
103
92
  },
104
- '@eslint/eslintrc': {
105
- type: NpmDepType.Dev,
106
- env: {
107
- [RuntimeEnv.Node]: true,
108
- [RuntimeEnv.Web]: true,
109
- },
110
- packageType: {
111
- [PackageType.TopPackage]: true,
112
- [PackageType.MonoRoot]: true,
113
- },
114
- },
115
93
  '@stylistic/eslint-plugin': {
116
94
  type: NpmDepType.Dev,
117
95
  env: {
@@ -0,0 +1,3 @@
1
+ import { type Rule } from 'eslint';
2
+ declare const rule: Rule.RuleModule;
3
+ export default rule;
@@ -0,0 +1,45 @@
1
+ import { existsSync } from 'node:fs';
2
+ import { dirname, resolve } from 'node:path';
3
+ const rule = {
4
+ meta: {
5
+ type: 'problem',
6
+ fixable: 'code',
7
+ messages: {
8
+ missingJsExtension: "Relative imports and exports must end with '.js'.",
9
+ },
10
+ schema: [],
11
+ },
12
+ create(context) {
13
+ function check(node) {
14
+ const source = node.source;
15
+ if (!source || typeof source.value !== 'string') {
16
+ return;
17
+ }
18
+ const rawValue = source.value;
19
+ const queryStart = rawValue.indexOf('?');
20
+ const valueWithoutQuery = queryStart === -1 ? rawValue : rawValue.slice(0, queryStart);
21
+ if (!valueWithoutQuery ||
22
+ !valueWithoutQuery.startsWith('.') ||
23
+ valueWithoutQuery.endsWith('.js')) {
24
+ return;
25
+ }
26
+ const absolutePath = resolve(dirname(context.filename), valueWithoutQuery);
27
+ if (existsSync(absolutePath)) {
28
+ return;
29
+ }
30
+ context.report({
31
+ node,
32
+ messageId: 'missingJsExtension',
33
+ fix: rawValue.includes('?')
34
+ ? null
35
+ : (fixer) => fixer.replaceText(source, `'${rawValue}.js'`),
36
+ });
37
+ }
38
+ return {
39
+ ImportDeclaration: check,
40
+ ExportAllDeclaration: check,
41
+ ExportNamedDeclaration: check,
42
+ };
43
+ },
44
+ };
45
+ export default rule;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@virmator/lint",
3
- "version": "14.21.3",
3
+ "version": "14.23.0",
4
4
  "description": "Default ESLint linting plugin for virmator.",
5
5
  "keywords": [
6
6
  "virmator",
@@ -35,13 +35,13 @@
35
35
  "@augment-vir/assert": "^31.71.3",
36
36
  "@augment-vir/common": "^31.71.3",
37
37
  "@augment-vir/node": "^31.71.3",
38
- "@virmator/core": "^14.21.3",
38
+ "@virmator/core": "^14.23.0",
39
+ "globals": "^17.6.0",
39
40
  "jiti": "^2.7.0",
40
41
  "mri": "^1.2.0"
41
42
  },
42
43
  "devDependencies": {
43
44
  "@augment-vir/test": "^31.71.3",
44
- "@eslint/eslintrc": "^3.3.5",
45
45
  "@eslint/js": "10.0.1",
46
46
  "@stylistic/eslint-plugin": "^5.10.0",
47
47
  "@stylistic/eslint-plugin-ts": "^4.4.1",
@@ -54,7 +54,6 @@
54
54
  "eslint-plugin-jsdoc": "^63.0.0",
55
55
  "eslint-plugin-playwright": "^2.10.4",
56
56
  "eslint-plugin-prettier": "^5.5.6",
57
- "eslint-plugin-require-extensions": "^0.1.3",
58
57
  "eslint-plugin-sonarjs": "^4.0.3",
59
58
  "eslint-plugin-unicorn": "^64.0.0",
60
59
  "istanbul-smart-text-reporter": "^1.1.5",
package/src/lint.ts CHANGED
@@ -71,17 +71,6 @@ export const virmatorLintPlugin = defineVirmatorPlugin(
71
71
  [PackageType.MonoRoot]: true,
72
72
  },
73
73
  },
74
- 'eslint-plugin-require-extensions': {
75
- type: NpmDepType.Dev,
76
- env: {
77
- [RuntimeEnv.Node]: true,
78
- [RuntimeEnv.Web]: true,
79
- },
80
- packageType: {
81
- [PackageType.TopPackage]: true,
82
- [PackageType.MonoRoot]: true,
83
- },
84
- },
85
74
  'eslint-plugin-unicorn': {
86
75
  type: NpmDepType.Dev,
87
76
  env: {
@@ -104,17 +93,6 @@ export const virmatorLintPlugin = defineVirmatorPlugin(
104
93
  [PackageType.MonoRoot]: true,
105
94
  },
106
95
  },
107
- '@eslint/eslintrc': {
108
- type: NpmDepType.Dev,
109
- env: {
110
- [RuntimeEnv.Node]: true,
111
- [RuntimeEnv.Web]: true,
112
- },
113
- packageType: {
114
- [PackageType.TopPackage]: true,
115
- [PackageType.MonoRoot]: true,
116
- },
117
- },
118
96
  '@stylistic/eslint-plugin': {
119
97
  type: NpmDepType.Dev,
120
98
  env: {
@@ -0,0 +1,58 @@
1
+ import {type Rule} from 'eslint';
2
+ import type {ExportAllDeclaration, ExportNamedDeclaration, ImportDeclaration} from 'estree';
3
+ import {existsSync} from 'node:fs';
4
+ import {dirname, resolve} from 'node:path';
5
+
6
+ type SourceNode = ImportDeclaration | ExportAllDeclaration | ExportNamedDeclaration;
7
+
8
+ const rule: Rule.RuleModule = {
9
+ meta: {
10
+ type: 'problem',
11
+ fixable: 'code',
12
+ messages: {
13
+ missingJsExtension: "Relative imports and exports must end with '.js'.",
14
+ },
15
+ schema: [],
16
+ },
17
+ create(context) {
18
+ function check(node: SourceNode): void {
19
+ const source = node.source;
20
+ if (!source || typeof source.value !== 'string') {
21
+ return;
22
+ }
23
+
24
+ const rawValue = source.value;
25
+ const queryStart = rawValue.indexOf('?');
26
+ const valueWithoutQuery = queryStart === -1 ? rawValue : rawValue.slice(0, queryStart);
27
+
28
+ if (
29
+ !valueWithoutQuery ||
30
+ !valueWithoutQuery.startsWith('.') ||
31
+ valueWithoutQuery.endsWith('.js')
32
+ ) {
33
+ return;
34
+ }
35
+
36
+ const absolutePath = resolve(dirname(context.filename), valueWithoutQuery);
37
+ if (existsSync(absolutePath)) {
38
+ return;
39
+ }
40
+
41
+ context.report({
42
+ node,
43
+ messageId: 'missingJsExtension',
44
+ fix: rawValue.includes('?')
45
+ ? null
46
+ : (fixer) => fixer.replaceText(source, `'${rawValue}.js'`),
47
+ });
48
+ }
49
+
50
+ return {
51
+ ImportDeclaration: check,
52
+ ExportAllDeclaration: check,
53
+ ExportNamedDeclaration: check,
54
+ };
55
+ },
56
+ };
57
+
58
+ export default rule;