auto-cr-rules 2.0.34 → 2.0.35
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.
|
@@ -25,9 +25,11 @@ exports.noDeepRelativeImports = (0, types_1.defineRule)('no-deep-relative-import
|
|
|
25
25
|
{ text: 'Use a path alias (for example: @shared/deep/utils).' },
|
|
26
26
|
{ text: 'Create an index file at a higher level to re-export the module and shorten the import.' },
|
|
27
27
|
];
|
|
28
|
-
var
|
|
28
|
+
var computedLine = reference.span
|
|
29
29
|
? resolveLine(lineIndex, bytePosToCharIndex(source, moduleStart, reference.span.start))
|
|
30
30
|
: undefined;
|
|
31
|
+
var fallbackLine = findImportLine(source, reference.value);
|
|
32
|
+
var line = selectLineNumber(computedLine, fallbackLine);
|
|
31
33
|
helpers.reportViolation({
|
|
32
34
|
description: description,
|
|
33
35
|
code: reference.value,
|
|
@@ -98,3 +100,25 @@ var bytePosToCharIndex = function (source, moduleStart, bytePos) {
|
|
|
98
100
|
}
|
|
99
101
|
return source.length;
|
|
100
102
|
};
|
|
103
|
+
var findImportLine = function (source, value) {
|
|
104
|
+
var lines = source.split(/\r?\n/);
|
|
105
|
+
for (var index = 0; index < lines.length; index += 1) {
|
|
106
|
+
var line = lines[index];
|
|
107
|
+
if (line.includes('import') && line.includes(value)) {
|
|
108
|
+
return index + 1;
|
|
109
|
+
}
|
|
110
|
+
}
|
|
111
|
+
return undefined;
|
|
112
|
+
};
|
|
113
|
+
var selectLineNumber = function (computed, fallback) {
|
|
114
|
+
if (fallback === undefined) {
|
|
115
|
+
return computed;
|
|
116
|
+
}
|
|
117
|
+
if (computed === undefined) {
|
|
118
|
+
return fallback;
|
|
119
|
+
}
|
|
120
|
+
if (computed < fallback) {
|
|
121
|
+
return fallback;
|
|
122
|
+
}
|
|
123
|
+
return computed;
|
|
124
|
+
};
|
package/package.json
CHANGED