-
Notifications
You must be signed in to change notification settings - Fork 25
/
Copy pathindex.js
38 lines (33 loc) · 850 Bytes
/
index.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
function isParentFolder(path) {
return path.startsWith("../");
}
function isSameFolder(path) {
return path.startsWith("./");
}
const message = "import statements should have an absolute path";
module.exports = {
rules: {
"no-relative-imports": {
create: function (context) {
const { allowSameFolder } = context.options[0] || {};
return {
ImportDeclaration: function (node) {
const path = node.source.value;
if (isParentFolder(path)) {
context.report({
node,
message: message,
});
}
if (isSameFolder(path) && !allowSameFolder) {
context.report({
node,
message: message,
});
}
},
};
},
},
},
};