@planfredapp/eslint-config 1.1.3 → 1.2.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/no-relative-import-paths.js +117 -0
- package/package.json +6 -7
- package/vue.js +1 -1
|
@@ -0,0 +1,117 @@
|
|
|
1
|
+
import path from 'node:path'
|
|
2
|
+
|
|
3
|
+
function isParentFolder (relativeFilePath, cwd, filename, rootDir) {
|
|
4
|
+
const absoluteRootPath = path.join(cwd, rootDir)
|
|
5
|
+
const absoluteFilePath = path.join(path.dirname(filename), relativeFilePath)
|
|
6
|
+
|
|
7
|
+
return relativeFilePath.startsWith('../') && (
|
|
8
|
+
rootDir === '' ||
|
|
9
|
+
(absoluteFilePath.startsWith(absoluteRootPath) &&
|
|
10
|
+
filename.startsWith(absoluteRootPath))
|
|
11
|
+
)
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
function isSameFolder (importPath) {
|
|
15
|
+
return importPath.startsWith('./')
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
function getRelativePathDepth (importPath) {
|
|
19
|
+
let depth = 0
|
|
20
|
+
|
|
21
|
+
while (importPath.startsWith('../')) {
|
|
22
|
+
depth += 1
|
|
23
|
+
importPath = importPath.substring(3)
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
return depth
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
function getAbsolutePath (relativePath, cwd, filename, rootDir, prefix) {
|
|
30
|
+
return [
|
|
31
|
+
prefix,
|
|
32
|
+
...path
|
|
33
|
+
.relative(
|
|
34
|
+
path.join(cwd, rootDir),
|
|
35
|
+
path.join(path.dirname(filename), relativePath),
|
|
36
|
+
)
|
|
37
|
+
.split(path.sep),
|
|
38
|
+
].filter(String)
|
|
39
|
+
.join('/')
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
export default {
|
|
43
|
+
rules: {
|
|
44
|
+
'no-relative-import-paths': {
|
|
45
|
+
meta: {
|
|
46
|
+
type: 'layout',
|
|
47
|
+
fixable: 'code',
|
|
48
|
+
schema: [
|
|
49
|
+
{
|
|
50
|
+
type: 'object',
|
|
51
|
+
properties: {
|
|
52
|
+
allowSameFolder: { type: 'boolean' },
|
|
53
|
+
rootDir: { type: 'string' },
|
|
54
|
+
prefix: { type: 'string' },
|
|
55
|
+
allowedDepth: { type: 'number' },
|
|
56
|
+
},
|
|
57
|
+
additionalProperties: false,
|
|
58
|
+
},
|
|
59
|
+
],
|
|
60
|
+
messages: {
|
|
61
|
+
noRelativeImportPaths: 'Import statements should use absolute paths.',
|
|
62
|
+
},
|
|
63
|
+
},
|
|
64
|
+
create (context) {
|
|
65
|
+
const {
|
|
66
|
+
allowedDepth,
|
|
67
|
+
allowSameFolder = false,
|
|
68
|
+
rootDir = '',
|
|
69
|
+
prefix = '',
|
|
70
|
+
} = context.options[0] ?? {}
|
|
71
|
+
|
|
72
|
+
const cwd = context.cwd
|
|
73
|
+
const filename = context.filename
|
|
74
|
+
|
|
75
|
+
return {
|
|
76
|
+
ImportDeclaration (node) {
|
|
77
|
+
const importPath = node.source.value
|
|
78
|
+
|
|
79
|
+
if (isParentFolder(importPath, cwd, filename, rootDir)) {
|
|
80
|
+
if (typeof allowedDepth === 'undefined' || getRelativePathDepth(importPath) > allowedDepth) {
|
|
81
|
+
context.report({
|
|
82
|
+
node,
|
|
83
|
+
messageId: 'noRelativeImportPaths',
|
|
84
|
+
fix (fixer) {
|
|
85
|
+
return fixer.replaceTextRange(
|
|
86
|
+
[
|
|
87
|
+
node.source.range[0] + 1,
|
|
88
|
+
node.source.range[1] - 1,
|
|
89
|
+
],
|
|
90
|
+
getAbsolutePath(importPath, cwd, filename, rootDir, prefix),
|
|
91
|
+
)
|
|
92
|
+
},
|
|
93
|
+
})
|
|
94
|
+
}
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
if (isSameFolder(importPath) && !allowSameFolder) {
|
|
98
|
+
context.report({
|
|
99
|
+
node,
|
|
100
|
+
messageId: 'noRelativeImportPaths',
|
|
101
|
+
fix (fixer) {
|
|
102
|
+
return fixer.replaceTextRange(
|
|
103
|
+
[
|
|
104
|
+
node.source.range[0] + 1,
|
|
105
|
+
node.source.range[1] - 1,
|
|
106
|
+
],
|
|
107
|
+
getAbsolutePath(importPath, cwd, filename, rootDir, prefix),
|
|
108
|
+
)
|
|
109
|
+
},
|
|
110
|
+
})
|
|
111
|
+
}
|
|
112
|
+
},
|
|
113
|
+
}
|
|
114
|
+
},
|
|
115
|
+
},
|
|
116
|
+
},
|
|
117
|
+
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@planfredapp/eslint-config",
|
|
3
|
-
"version": "1.1
|
|
3
|
+
"version": "1.2.1",
|
|
4
4
|
"description": "Shared ESLint 10 configurations for Planfred monorepo",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"eslint",
|
|
@@ -50,21 +50,20 @@
|
|
|
50
50
|
"dependencies": {
|
|
51
51
|
"@eslint/js": "10.0.1",
|
|
52
52
|
"@stylistic/eslint-plugin": "5.10.0",
|
|
53
|
-
"@vitest/eslint-plugin": "1.6.
|
|
54
|
-
"eslint-plugin-cypress": "6.
|
|
53
|
+
"@vitest/eslint-plugin": "1.6.15",
|
|
54
|
+
"eslint-plugin-cypress": "6.3.0",
|
|
55
55
|
"eslint-plugin-import-x": "4.16.2",
|
|
56
56
|
"eslint-plugin-n": "17.24.0",
|
|
57
57
|
"eslint-plugin-no-only-tests": "3.3.0",
|
|
58
|
-
"eslint-plugin-no-relative-import-paths": "1.6.1",
|
|
59
58
|
"eslint-plugin-vue": "10.8.0",
|
|
60
59
|
"globals": "17.4.0",
|
|
61
|
-
"typescript-eslint": "8.58.
|
|
60
|
+
"typescript-eslint": "8.58.1",
|
|
62
61
|
"vue-eslint-parser": "10.4.0"
|
|
63
62
|
},
|
|
64
63
|
"devDependencies": {
|
|
65
|
-
"eslint": "10.
|
|
64
|
+
"eslint": "10.2.0",
|
|
66
65
|
"typescript": "6.0.2",
|
|
67
|
-
"vitest": "4.1.
|
|
66
|
+
"vitest": "4.1.4"
|
|
68
67
|
},
|
|
69
68
|
"peerDependencies": {
|
|
70
69
|
"eslint": ">=10.0.0"
|
package/vue.js
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
/** @type {import('eslint').Linter.Config[]} */
|
|
2
|
-
import noRelativeImportPathsPlugin from 'eslint-plugin-no-relative-import-paths'
|
|
3
2
|
import vuePlugin from 'eslint-plugin-vue'
|
|
4
3
|
|
|
5
4
|
import baseConfig from './base.js'
|
|
5
|
+
import noRelativeImportPathsPlugin from './no-relative-import-paths.js'
|
|
6
6
|
|
|
7
7
|
export default [
|
|
8
8
|
...baseConfig,
|