ember-eslint-parser 0.8.0 → 0.10.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/package.json +13 -11
- package/src/parser/gjs-gts-parser.js +116 -87
- package/src/parser/hbs-parser.js +69 -68
- package/src/parser/transforms.js +162 -597
- package/src/parser/ts-patch.js +6 -9
- package/src/preprocessor/noop.js +23 -20
- package/src/utils/document.js +0 -102
package/src/parser/ts-patch.js
CHANGED
|
@@ -1,6 +1,8 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
1
|
+
import fs from 'node:fs';
|
|
2
|
+
import { createRequire } from 'node:module';
|
|
3
|
+
import { transformForLint, replaceRange } from './transforms.js';
|
|
4
|
+
|
|
5
|
+
const require = createRequire(import.meta.url);
|
|
4
6
|
|
|
5
7
|
let patchTs, replaceExtensions, syncMtsGtsSourceFiles, typescriptParser, isPatched, allowGjs;
|
|
6
8
|
|
|
@@ -162,9 +164,4 @@ try {
|
|
|
162
164
|
syncMtsGtsSourceFiles = () => null;
|
|
163
165
|
}
|
|
164
166
|
|
|
165
|
-
|
|
166
|
-
patchTs,
|
|
167
|
-
replaceExtensions,
|
|
168
|
-
syncMtsGtsSourceFiles,
|
|
169
|
-
typescriptParser,
|
|
170
|
-
};
|
|
167
|
+
export { patchTs, replaceExtensions, syncMtsGtsSourceFiles, typescriptParser };
|
package/src/preprocessor/noop.js
CHANGED
|
@@ -9,24 +9,27 @@
|
|
|
9
9
|
|
|
10
10
|
const parsedFiles = new Set();
|
|
11
11
|
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
supportsAutofix: true,
|
|
12
|
+
export function registerParsedFile(f) {
|
|
13
|
+
parsedFiles.add(f);
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
export const preprocess = undefined;
|
|
17
|
+
|
|
18
|
+
export const postprocess = (messages, fileName) => {
|
|
19
|
+
const msgs = messages.flat();
|
|
20
|
+
if (!parsedFiles.has(fileName)) {
|
|
21
|
+
msgs[0] = msgs[0] || {
|
|
22
|
+
message: '',
|
|
23
|
+
};
|
|
24
|
+
msgs[0].message += '\n';
|
|
25
|
+
msgs[0].message +=
|
|
26
|
+
'To lint Gjs/Gts files please follow the setup guide at https://github.com/ember-cli/eslint-plugin-ember#gtsgjs' +
|
|
27
|
+
'\nNote that this error can also happen if you have multiple versions of eslint-plugin-ember in your node_modules';
|
|
28
|
+
}
|
|
29
|
+
parsedFiles.delete(fileName); // required for tests
|
|
30
|
+
return msgs;
|
|
32
31
|
};
|
|
32
|
+
|
|
33
|
+
export const supportsAutofix = true;
|
|
34
|
+
|
|
35
|
+
export default { registerParsedFile, preprocess, postprocess, supportsAutofix };
|
package/src/utils/document.js
DELETED
|
@@ -1,102 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* @typedef {{ line: number; column: number }} Position
|
|
3
|
-
*/
|
|
4
|
-
|
|
5
|
-
// Helper class to convert line/column from and to offset
|
|
6
|
-
// taken and adapt from https://github.com/typed-ember/glint/blob/main/packages/core/src/language-server/util/position.ts
|
|
7
|
-
class DocumentLines {
|
|
8
|
-
/**
|
|
9
|
-
* @param {string} contents
|
|
10
|
-
*/
|
|
11
|
-
constructor(contents) {
|
|
12
|
-
this.lineStarts = computeLineStarts(contents);
|
|
13
|
-
}
|
|
14
|
-
|
|
15
|
-
/**
|
|
16
|
-
* @param {Position} position
|
|
17
|
-
* @return {number}
|
|
18
|
-
*/
|
|
19
|
-
positionToOffset(position) {
|
|
20
|
-
const { line, column } = position;
|
|
21
|
-
return this.lineStarts[line - 1] + column;
|
|
22
|
-
}
|
|
23
|
-
|
|
24
|
-
/**
|
|
25
|
-
*
|
|
26
|
-
* @param {number} position
|
|
27
|
-
* @return {Position}
|
|
28
|
-
*/
|
|
29
|
-
offsetToPosition(position) {
|
|
30
|
-
const lineStarts = this.lineStarts;
|
|
31
|
-
let lo = 0;
|
|
32
|
-
let hi = lineStarts.length - 1;
|
|
33
|
-
// Upper-biased midpoint is required here: we want the *rightmost* line whose
|
|
34
|
-
// start is ≤ position. With a lower-biased mid, when lo + 1 === hi and the
|
|
35
|
-
// condition is true, mid === lo and lo never advances, causing an infinite loop.
|
|
36
|
-
while (lo < hi) {
|
|
37
|
-
const mid = (lo + hi + 1) >> 1;
|
|
38
|
-
if (lineStarts[mid] <= position) {
|
|
39
|
-
lo = mid;
|
|
40
|
-
} else {
|
|
41
|
-
hi = mid - 1;
|
|
42
|
-
}
|
|
43
|
-
}
|
|
44
|
-
return { line: lo + 1, column: position - lineStarts[lo] };
|
|
45
|
-
}
|
|
46
|
-
}
|
|
47
|
-
|
|
48
|
-
/**
|
|
49
|
-
* @returns {number[]}
|
|
50
|
-
* @param {string} text
|
|
51
|
-
*/
|
|
52
|
-
function computeLineStarts(text) {
|
|
53
|
-
const result = [];
|
|
54
|
-
let pos = 0;
|
|
55
|
-
let lineStart = 0;
|
|
56
|
-
while (pos < text.length) {
|
|
57
|
-
const ch = text.charCodeAt(pos++);
|
|
58
|
-
if (ch === 13 /* carriageReturn */) {
|
|
59
|
-
if (text.charCodeAt(pos) === 10 /* lineFeed */) {
|
|
60
|
-
pos++;
|
|
61
|
-
}
|
|
62
|
-
result.push(lineStart);
|
|
63
|
-
lineStart = pos;
|
|
64
|
-
} else if (
|
|
65
|
-
ch === 10 /* lineFeed */ ||
|
|
66
|
-
ch === 8232 /* lineSeparator */ ||
|
|
67
|
-
ch === 8233 /* paragraphSeparator */
|
|
68
|
-
) {
|
|
69
|
-
result.push(lineStart);
|
|
70
|
-
lineStart = pos;
|
|
71
|
-
}
|
|
72
|
-
}
|
|
73
|
-
result.push(lineStart);
|
|
74
|
-
return result;
|
|
75
|
-
}
|
|
76
|
-
|
|
77
|
-
/* istanbul ignore next */
|
|
78
|
-
/**
|
|
79
|
-
* @param {number} ch
|
|
80
|
-
* @return {boolean}
|
|
81
|
-
*/
|
|
82
|
-
function isLineBreak(ch) {
|
|
83
|
-
// ES5 7.3:
|
|
84
|
-
// The ECMAScript line terminator characters are listed in Table 3.
|
|
85
|
-
// Table 3: Line Terminator Characters
|
|
86
|
-
// Code Unit Value Name Formal Name
|
|
87
|
-
// \u000A Line Feed <LF>
|
|
88
|
-
// \u000D Carriage Return <CR>
|
|
89
|
-
// \u2028 Line separator <LS>
|
|
90
|
-
// \u2029 Paragraph separator <PS>
|
|
91
|
-
// Only the characters in Table 3 are treated as line terminators. Other new line or line
|
|
92
|
-
// breaking characters are treated as white space but not as line terminators.
|
|
93
|
-
return (
|
|
94
|
-
ch === 10 /* lineFeed */ ||
|
|
95
|
-
ch === 13 /* carriageReturn */ ||
|
|
96
|
-
ch === 8232 /* lineSeparator */ ||
|
|
97
|
-
ch === 8233 /* paragraphSeparator */
|
|
98
|
-
);
|
|
99
|
-
}
|
|
100
|
-
|
|
101
|
-
module.exports = DocumentLines;
|
|
102
|
-
module.exports.isLineBreak = isLineBreak;
|