@toptal/davinci-syntax 11.0.2 → 11.1.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/CHANGELOG.md +6 -0
- package/dist-package/package.json +1 -1
- package/package.json +1 -1
- package/src/{__snapshots__ → __tests__/__snapshots__}/eslint.test.ts.snap +3 -0
- package/src/__tests__/eslint-package-structure/bar.js +2 -0
- package/src/__tests__/eslint-package-structure/package/index.js +1 -0
- package/src/__tests__/eslint-package-structure/package/package.json +4 -0
- package/src/__tests__/eslint-package-structure/package-named/index.js +1 -0
- package/src/__tests__/eslint-package-structure/package-named/package.json +5 -0
- package/src/__tests__/eslint-package-structure/package-scoped/index.js +1 -0
- package/src/__tests__/eslint-package-structure/package-scoped/package.json +5 -0
- package/src/{eslint.test.ts → __tests__/eslint.test.ts} +2 -2
- package/src/__tests__/no-relative-packages.test.js +102 -0
- package/src/configs/.eslintrc +1 -0
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,11 @@
|
|
|
1
1
|
# Change Log
|
|
2
2
|
|
|
3
|
+
## 11.1.0
|
|
4
|
+
|
|
5
|
+
### Minor Changes
|
|
6
|
+
|
|
7
|
+
- [#1072](https://github.com/toptal/davinci/pull/1072) [`0b93a80c`](https://github.com/toptal/davinci/commit/0b93a80c005d723503cb9dd3520505a450dc0d0b) Thanks [@MrBra1nwash](https://github.com/MrBra1nwash)! - [SP-1771] Add import/no-relative-packages rule
|
|
8
|
+
|
|
3
9
|
## 11.0.2
|
|
4
10
|
|
|
5
11
|
### Patch Changes
|
package/package.json
CHANGED
|
@@ -184,6 +184,9 @@ exports[`eslint config verifies eslint rules are not updated silently 1`] = `
|
|
|
184
184
|
'import/no-extraneous-dependencies': [
|
|
185
185
|
'error',
|
|
186
186
|
],
|
|
187
|
+
'import/no-relative-packages': [
|
|
188
|
+
'warn',
|
|
189
|
+
],
|
|
187
190
|
'@typescript-eslint/array-type': [
|
|
188
191
|
'error',
|
|
189
192
|
{
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export default () => {}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export default () => {}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export default () => {}
|
|
@@ -3,8 +3,8 @@ import { ESLint, Linter } from 'eslint'
|
|
|
3
3
|
import json5 from 'json5'
|
|
4
4
|
|
|
5
5
|
const getConfig = () => {
|
|
6
|
-
const pathToEslintrc = path.join(__dirname, '
|
|
7
|
-
|
|
6
|
+
const pathToEslintrc = path.join(__dirname, '../../src/configs/.eslintrc')
|
|
7
|
+
|
|
8
8
|
return new ESLint({
|
|
9
9
|
useEslintrc: false, // don't use any other eslintrc files (higher in the folder tree)
|
|
10
10
|
overrideConfigFile: pathToEslintrc // use this exact eslintrc file
|
|
@@ -0,0 +1,102 @@
|
|
|
1
|
+
import { RuleTester } from 'eslint'
|
|
2
|
+
import path from 'path'
|
|
3
|
+
import rule from 'eslint-plugin-import/lib/rules/no-relative-packages'
|
|
4
|
+
|
|
5
|
+
const testFilePath = relativePath =>
|
|
6
|
+
path.join(__dirname, '/eslint-package-structure', relativePath)
|
|
7
|
+
|
|
8
|
+
const FILENAME = testFilePath('foo.js')
|
|
9
|
+
|
|
10
|
+
const testRule = options => ({
|
|
11
|
+
filename: FILENAME,
|
|
12
|
+
parserOptions: {
|
|
13
|
+
sourceType: 'module',
|
|
14
|
+
ecmaVersion: 9,
|
|
15
|
+
...options.parserOptions
|
|
16
|
+
},
|
|
17
|
+
...options
|
|
18
|
+
})
|
|
19
|
+
|
|
20
|
+
const ruleTester = new RuleTester()
|
|
21
|
+
|
|
22
|
+
ruleTester.run('no-relative-packages', rule, {
|
|
23
|
+
valid: [
|
|
24
|
+
testRule({
|
|
25
|
+
code: 'import foo from "./index.js"',
|
|
26
|
+
filename: testFilePath('./package/index.js')
|
|
27
|
+
}),
|
|
28
|
+
/**
|
|
29
|
+
* Unfortunately, this case is considered valid for the rule,
|
|
30
|
+
* but we cannot influence this. This case should be considered invalid.
|
|
31
|
+
*
|
|
32
|
+
* testRule({
|
|
33
|
+
* code: 'import bar from "../bar"',
|
|
34
|
+
* filename: testFilePath('./package/index.js')
|
|
35
|
+
* }),
|
|
36
|
+
*/
|
|
37
|
+
testRule({
|
|
38
|
+
code: 'import { foo } from "a"',
|
|
39
|
+
filename: testFilePath('./package-named/index.js')
|
|
40
|
+
}),
|
|
41
|
+
testRule({
|
|
42
|
+
code: 'const bar = require("../bar.js")',
|
|
43
|
+
filename: testFilePath('./package/index.js')
|
|
44
|
+
}),
|
|
45
|
+
testRule({
|
|
46
|
+
code: 'import "package"',
|
|
47
|
+
filename: testFilePath('./package/index.js')
|
|
48
|
+
}),
|
|
49
|
+
testRule({
|
|
50
|
+
code: 'require("../bar.js")',
|
|
51
|
+
filename: testFilePath('./package/index.js')
|
|
52
|
+
})
|
|
53
|
+
],
|
|
54
|
+
invalid: [
|
|
55
|
+
testRule({
|
|
56
|
+
code: 'import foo from "./package-named"',
|
|
57
|
+
filename: testFilePath('./bar.js'),
|
|
58
|
+
errors: [
|
|
59
|
+
{
|
|
60
|
+
message:
|
|
61
|
+
'Relative import from another package is not allowed. Use `package-named` instead of `./package-named`',
|
|
62
|
+
line: 1,
|
|
63
|
+
column: 17
|
|
64
|
+
}
|
|
65
|
+
]
|
|
66
|
+
}),
|
|
67
|
+
testRule({
|
|
68
|
+
code: 'import foo from "../package-named"',
|
|
69
|
+
filename: testFilePath('./package/index.js'),
|
|
70
|
+
errors: [
|
|
71
|
+
{
|
|
72
|
+
message:
|
|
73
|
+
'Relative import from another package is not allowed. Use `package-named` instead of `../package-named`',
|
|
74
|
+
line: 1,
|
|
75
|
+
column: 17
|
|
76
|
+
}
|
|
77
|
+
]
|
|
78
|
+
}),
|
|
79
|
+
testRule({
|
|
80
|
+
code: 'import foo from "../package-scoped"',
|
|
81
|
+
filename: testFilePath('./package/index.js'),
|
|
82
|
+
errors: [
|
|
83
|
+
{
|
|
84
|
+
message: `Relative import from another package is not allowed. Use \`@scope/package-named\` instead of \`../package-scoped\``,
|
|
85
|
+
line: 1,
|
|
86
|
+
column: 17
|
|
87
|
+
}
|
|
88
|
+
]
|
|
89
|
+
}),
|
|
90
|
+
testRule({
|
|
91
|
+
code: 'import bar from "../bar"',
|
|
92
|
+
filename: testFilePath('./package-named/index.js'),
|
|
93
|
+
errors: [
|
|
94
|
+
{
|
|
95
|
+
message: `Relative import from another package is not allowed. Use \`@toptal/davinci-syntax/src/__test__/eslint-package-structure/bar\` instead of \`../bar\``,
|
|
96
|
+
line: 1,
|
|
97
|
+
column: 17
|
|
98
|
+
}
|
|
99
|
+
]
|
|
100
|
+
})
|
|
101
|
+
]
|
|
102
|
+
})
|
package/src/configs/.eslintrc
CHANGED