@virmator/lint 14.19.1 → 14.20.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
@@ -19,7 +19,6 @@ A default plugin for [virmator](https://www.npmjs.com/package/virmator).
19
19
  - [@eslint/js](https://npmjs.com/package/@eslint/js)
20
20
  - [@eslint/eslintrc](https://npmjs.com/package/@eslint/eslintrc)
21
21
  - [@stylistic/eslint-plugin](https://npmjs.com/package/@stylistic/eslint-plugin)
22
- - [eslint-plugin-monorepo-cop](https://npmjs.com/package/eslint-plugin-monorepo-cop)
23
22
  - [@stylistic/eslint-plugin-ts](https://npmjs.com/package/@stylistic/eslint-plugin-ts)
24
23
  - [@typescript-eslint/eslint-plugin](https://npmjs.com/package/@typescript-eslint/eslint-plugin)
25
24
  - [eslint-config-prettier](https://npmjs.com/package/eslint-config-prettier)
@@ -7,6 +7,7 @@ import sonarJsEslint from 'eslint-plugin-sonarjs';
7
7
  import eslintPluginUnicorn from 'eslint-plugin-unicorn';
8
8
  import globals from 'globals';
9
9
  import tsEslint from 'typescript-eslint';
10
+ import noRelativeImportOutsidePackageRule from '../src/rules/no-relative-import-outside-package.lint.js';
10
11
  import preferIfElseChainRule from '../src/rules/prefer-if-else-chain.lint.js';
11
12
  import preferParseUrlRule from '../src/rules/prefer-parse-url.lint.js';
12
13
  import preferSingleQuotesRule from '../src/rules/prefer-single-quotes.lint.js';
@@ -24,12 +25,6 @@ export function defineEslintConfig(repoDir: string) {
24
25
  return [
25
26
  ...compat.plugins('require-extensions'),
26
27
  ...compat.extends('plugin:require-extensions/recommended'),
27
- ...compat.config({
28
- plugins: ['monorepo-cop'],
29
- rules: {
30
- 'monorepo-cop/no-relative-import-outside-package': 'error',
31
- },
32
- }),
33
28
  {
34
29
  ignores: [
35
30
  '*.graphql',
@@ -71,6 +66,7 @@ export function defineEslintConfig(repoDir: string) {
71
66
  unicorn: eslintPluginUnicorn,
72
67
  '@virmator': {
73
68
  rules: {
69
+ 'no-relative-import-outside-package': noRelativeImportOutsidePackageRule,
74
70
  'prefer-if-else-chain': preferIfElseChainRule,
75
71
  'prefer-parse-url': preferParseUrlRule,
76
72
  'prefer-single-quotes': preferSingleQuotesRule,
@@ -174,6 +170,7 @@ export function defineEslintConfig(repoDir: string) {
174
170
  '@jsdoc/no-undefined-types': 'error',
175
171
  '@typescript-eslint/await-thenable': 'error',
176
172
  '@typescript-eslint/no-unused-vars': 'error',
173
+ '@virmator/no-relative-import-outside-package': 'error',
177
174
  '@virmator/prefer-if-else-chain': 'error',
178
175
  '@virmator/prefer-parse-url': 'error',
179
176
  '@virmator/prefer-single-quotes': 'error',
package/dist/lint.d.ts CHANGED
@@ -103,17 +103,6 @@ export declare const virmatorLintPlugin: Readonly<Readonly<{
103
103
  readonly "mono-root": true;
104
104
  };
105
105
  };
106
- readonly 'eslint-plugin-monorepo-cop': {
107
- readonly type: NpmDepType.Dev;
108
- readonly env: {
109
- readonly node: true;
110
- readonly web: true;
111
- };
112
- readonly packageType: {
113
- readonly package: true;
114
- readonly "mono-root": true;
115
- };
116
- };
117
106
  readonly '@stylistic/eslint-plugin-ts': {
118
107
  readonly type: NpmDepType.Dev;
119
108
  readonly env: {
@@ -308,17 +297,6 @@ export declare const virmatorLintPlugin: Readonly<Readonly<{
308
297
  readonly "mono-root": true;
309
298
  };
310
299
  };
311
- readonly 'eslint-plugin-monorepo-cop': {
312
- readonly type: NpmDepType.Dev;
313
- readonly env: {
314
- readonly node: true;
315
- readonly web: true;
316
- };
317
- readonly packageType: {
318
- readonly package: true;
319
- readonly "mono-root": true;
320
- };
321
- };
322
300
  readonly '@stylistic/eslint-plugin-ts': {
323
301
  readonly type: NpmDepType.Dev;
324
302
  readonly env: {
package/dist/lint.js CHANGED
@@ -123,17 +123,6 @@ export const virmatorLintPlugin = defineVirmatorPlugin(import.meta.dirname, {
123
123
  [PackageType.MonoRoot]: true,
124
124
  },
125
125
  },
126
- 'eslint-plugin-monorepo-cop': {
127
- type: NpmDepType.Dev,
128
- env: {
129
- [RuntimeEnv.Node]: true,
130
- [RuntimeEnv.Web]: true,
131
- },
132
- packageType: {
133
- [PackageType.TopPackage]: true,
134
- [PackageType.MonoRoot]: true,
135
- },
136
- },
137
126
  '@stylistic/eslint-plugin-ts': {
138
127
  type: NpmDepType.Dev,
139
128
  env: {
@@ -0,0 +1,3 @@
1
+ import { type Rule } from 'eslint';
2
+ declare const rule: Rule.RuleModule;
3
+ export default rule;
@@ -0,0 +1,100 @@
1
+ import { existsSync, readFileSync } from 'node:fs';
2
+ import { dirname, isAbsolute, relative, resolve } from 'node:path';
3
+ const packageInfoCache = new Map();
4
+ function findPackageInfo(currentDir) {
5
+ const candidate = resolve(currentDir, 'package.json');
6
+ if (existsSync(candidate)) {
7
+ const parsed = JSON.parse(readFileSync(candidate, 'utf8'));
8
+ return {
9
+ dir: currentDir,
10
+ name: parsed.name || currentDir,
11
+ };
12
+ }
13
+ const parentDir = dirname(currentDir);
14
+ if (parentDir === currentDir) {
15
+ return undefined;
16
+ }
17
+ return findPackageInfo(parentDir);
18
+ }
19
+ function getPackageInfo(fileDir) {
20
+ const cached = packageInfoCache.get(fileDir);
21
+ if (cached || packageInfoCache.has(fileDir)) {
22
+ return cached;
23
+ }
24
+ const info = findPackageInfo(fileDir);
25
+ packageInfoCache.set(fileDir, info);
26
+ return info;
27
+ }
28
+ function isRelativeImport(specifier) {
29
+ return (specifier === '.' ||
30
+ specifier === '..' ||
31
+ specifier.startsWith('./') ||
32
+ specifier.startsWith('../'));
33
+ }
34
+ function isWithinDir(target, baseDir) {
35
+ if (target === baseDir) {
36
+ return true;
37
+ }
38
+ const rel = relative(baseDir, target);
39
+ return rel !== '' && !rel.startsWith('..') && !isAbsolute(rel);
40
+ }
41
+ function isTypeOnlyImport(node) {
42
+ const importKind = node.importKind;
43
+ return importKind === 'type';
44
+ }
45
+ function checkImport(context, importPath, node) {
46
+ if (!isRelativeImport(importPath)) {
47
+ return;
48
+ }
49
+ const fileDir = dirname(context.filename);
50
+ const packageInfo = getPackageInfo(fileDir);
51
+ if (!packageInfo) {
52
+ return;
53
+ }
54
+ const resolvedImport = resolve(fileDir, importPath);
55
+ if (isWithinDir(resolvedImport, packageInfo.dir)) {
56
+ return;
57
+ }
58
+ context.report({
59
+ node,
60
+ messageId: 'reachesOutsidePackage',
61
+ data: {
62
+ importPath,
63
+ packageName: packageInfo.name,
64
+ },
65
+ });
66
+ }
67
+ const rule = {
68
+ meta: {
69
+ type: 'problem',
70
+ messages: {
71
+ reachesOutsidePackage: 'import of "{{importPath}}" reaches outside of the package "{{packageName}}"',
72
+ },
73
+ schema: [],
74
+ },
75
+ create(context) {
76
+ return {
77
+ ImportDeclaration(node) {
78
+ if (isTypeOnlyImport(node)) {
79
+ return;
80
+ }
81
+ const source = node.source.value;
82
+ if (typeof source !== 'string') {
83
+ return;
84
+ }
85
+ checkImport(context, source, node);
86
+ },
87
+ CallExpression(node) {
88
+ if (node.callee.type !== 'Identifier' || node.callee.name !== 'require') {
89
+ return;
90
+ }
91
+ const arg = node.arguments[0];
92
+ if (!arg || arg.type !== 'Literal' || typeof arg.value !== 'string') {
93
+ return;
94
+ }
95
+ checkImport(context, arg.value, node);
96
+ },
97
+ };
98
+ },
99
+ };
100
+ export default rule;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@virmator/lint",
3
- "version": "14.19.1",
3
+ "version": "14.20.0",
4
4
  "description": "Default ESLint linting plugin for virmator.",
5
5
  "keywords": [
6
6
  "virmator",
@@ -15,7 +15,7 @@
15
15
  "type": "git",
16
16
  "url": "git+https://github.com/electrovir/virmator.git"
17
17
  },
18
- "license": "(MIT or CC0 1.0)",
18
+ "license": "(MIT OR CC0-1.0)",
19
19
  "author": {
20
20
  "name": "electrovir",
21
21
  "url": "https://github.com/electrovir"
@@ -32,34 +32,33 @@
32
32
  "test:update": "npm test update"
33
33
  },
34
34
  "dependencies": {
35
- "@augment-vir/assert": "^31.69.0",
36
- "@augment-vir/common": "^31.69.0",
37
- "@augment-vir/node": "^31.69.0",
38
- "@virmator/core": "^14.19.1",
39
- "jiti": "^2.6.1",
35
+ "@augment-vir/assert": "^31.71.3",
36
+ "@augment-vir/common": "^31.71.3",
37
+ "@augment-vir/node": "^31.71.3",
38
+ "@virmator/core": "^14.20.0",
39
+ "jiti": "^2.7.0",
40
40
  "mri": "^1.2.0"
41
41
  },
42
42
  "devDependencies": {
43
- "@augment-vir/test": "^31.69.0",
43
+ "@augment-vir/test": "^31.71.3",
44
44
  "@eslint/eslintrc": "^3.3.5",
45
- "@eslint/js": "9.39.2",
45
+ "@eslint/js": "10.0.1",
46
46
  "@stylistic/eslint-plugin": "^5.10.0",
47
47
  "@stylistic/eslint-plugin-ts": "^4.4.1",
48
- "@types/estree": "^1.0.8",
49
- "@types/node": "^25.6.0",
50
- "@typescript-eslint/eslint-plugin": "^8.58.0",
48
+ "@types/estree": "^1.0.9",
49
+ "@types/node": "^25.9.1",
50
+ "@typescript-eslint/eslint-plugin": "^8.60.0",
51
51
  "c8": "^11.0.0",
52
- "eslint": "^9.39.2",
52
+ "eslint": "^10.4.0",
53
53
  "eslint-config-prettier": "^10.1.8",
54
- "eslint-plugin-jsdoc": "^62.9.0",
55
- "eslint-plugin-monorepo-cop": "^1.0.2",
56
- "eslint-plugin-playwright": "^2.10.2",
57
- "eslint-plugin-prettier": "^5.5.5",
54
+ "eslint-plugin-jsdoc": "^63.0.0",
55
+ "eslint-plugin-playwright": "^2.10.4",
56
+ "eslint-plugin-prettier": "^5.5.6",
58
57
  "eslint-plugin-require-extensions": "^0.1.3",
59
58
  "eslint-plugin-sonarjs": "^4.0.3",
60
59
  "eslint-plugin-unicorn": "^64.0.0",
61
60
  "istanbul-smart-text-reporter": "^1.1.5",
62
- "typescript-eslint": "8.57.1"
61
+ "typescript-eslint": "^8.60.0"
63
62
  },
64
63
  "engines": {
65
64
  "node": ">=22"
package/src/lint.ts CHANGED
@@ -126,17 +126,6 @@ export const virmatorLintPlugin = defineVirmatorPlugin(
126
126
  [PackageType.MonoRoot]: true,
127
127
  },
128
128
  },
129
- 'eslint-plugin-monorepo-cop': {
130
- type: NpmDepType.Dev,
131
- env: {
132
- [RuntimeEnv.Node]: true,
133
- [RuntimeEnv.Web]: true,
134
- },
135
- packageType: {
136
- [PackageType.TopPackage]: true,
137
- [PackageType.MonoRoot]: true,
138
- },
139
- },
140
129
  '@stylistic/eslint-plugin-ts': {
141
130
  type: NpmDepType.Dev,
142
131
  env: {
@@ -0,0 +1,126 @@
1
+ import {type Rule} from 'eslint';
2
+ import type {CallExpression, ImportDeclaration} from 'estree';
3
+ import {existsSync, readFileSync} from 'node:fs';
4
+ import {dirname, isAbsolute, relative, resolve} from 'node:path';
5
+
6
+ type PackageInfo = {
7
+ dir: string;
8
+ name: string;
9
+ };
10
+
11
+ const packageInfoCache = new Map<string, PackageInfo | undefined>();
12
+
13
+ function findPackageInfo(currentDir: string): PackageInfo | undefined {
14
+ const candidate = resolve(currentDir, 'package.json');
15
+ if (existsSync(candidate)) {
16
+ const parsed = JSON.parse(readFileSync(candidate, 'utf8')) as {name?: string};
17
+ return {
18
+ dir: currentDir,
19
+ name: parsed.name || currentDir,
20
+ };
21
+ }
22
+ const parentDir = dirname(currentDir);
23
+ if (parentDir === currentDir) {
24
+ return undefined;
25
+ }
26
+ return findPackageInfo(parentDir);
27
+ }
28
+
29
+ function getPackageInfo(fileDir: string): PackageInfo | undefined {
30
+ const cached = packageInfoCache.get(fileDir);
31
+ if (cached || packageInfoCache.has(fileDir)) {
32
+ return cached;
33
+ }
34
+ const info = findPackageInfo(fileDir);
35
+ packageInfoCache.set(fileDir, info);
36
+ return info;
37
+ }
38
+
39
+ function isRelativeImport(specifier: string): boolean {
40
+ return (
41
+ specifier === '.' ||
42
+ specifier === '..' ||
43
+ specifier.startsWith('./') ||
44
+ specifier.startsWith('../')
45
+ );
46
+ }
47
+
48
+ function isWithinDir(target: string, baseDir: string): boolean {
49
+ if (target === baseDir) {
50
+ return true;
51
+ }
52
+ const rel: string = relative(baseDir, target);
53
+ return rel !== '' && !rel.startsWith('..') && !isAbsolute(rel);
54
+ }
55
+
56
+ function isTypeOnlyImport(node: ImportDeclaration): boolean {
57
+ const importKind = (node as {importKind?: unknown}).importKind;
58
+ return importKind === 'type';
59
+ }
60
+
61
+ function checkImport(
62
+ context: Rule.RuleContext,
63
+ importPath: string,
64
+ node: ImportDeclaration | CallExpression,
65
+ ): void {
66
+ if (!isRelativeImport(importPath)) {
67
+ return;
68
+ }
69
+
70
+ const fileDir = dirname(context.filename);
71
+ const packageInfo = getPackageInfo(fileDir);
72
+ if (!packageInfo) {
73
+ return;
74
+ }
75
+
76
+ const resolvedImport = resolve(fileDir, importPath);
77
+ if (isWithinDir(resolvedImport, packageInfo.dir)) {
78
+ return;
79
+ }
80
+
81
+ context.report({
82
+ node,
83
+ messageId: 'reachesOutsidePackage',
84
+ data: {
85
+ importPath,
86
+ packageName: packageInfo.name,
87
+ },
88
+ });
89
+ }
90
+
91
+ const rule: Rule.RuleModule = {
92
+ meta: {
93
+ type: 'problem',
94
+ messages: {
95
+ reachesOutsidePackage:
96
+ 'import of "{{importPath}}" reaches outside of the package "{{packageName}}"',
97
+ },
98
+ schema: [],
99
+ },
100
+ create(context) {
101
+ return {
102
+ ImportDeclaration(node: ImportDeclaration) {
103
+ if (isTypeOnlyImport(node)) {
104
+ return;
105
+ }
106
+ const source = node.source.value;
107
+ if (typeof source !== 'string') {
108
+ return;
109
+ }
110
+ checkImport(context, source, node);
111
+ },
112
+ CallExpression(node: CallExpression) {
113
+ if (node.callee.type !== 'Identifier' || node.callee.name !== 'require') {
114
+ return;
115
+ }
116
+ const arg = node.arguments[0];
117
+ if (!arg || arg.type !== 'Literal' || typeof arg.value !== 'string') {
118
+ return;
119
+ }
120
+ checkImport(context, arg.value, node);
121
+ },
122
+ };
123
+ },
124
+ };
125
+
126
+ export default rule;
package/tsconfig.json CHANGED
@@ -1,7 +1,10 @@
1
1
  {
2
2
  "compilerOptions": {
3
3
  "outDir": "./dist",
4
- "rootDir": "./src"
4
+ "rootDir": "./src",
5
+ "types": [
6
+ "node"
7
+ ]
5
8
  },
6
9
  "exclude": [
7
10
  "./configs",