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.
@@ -1,6 +1,8 @@
1
- const fs = require('node:fs');
2
- const { transformForLint } = require('./transforms');
3
- const { replaceRange } = require('./transforms');
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
- module.exports = {
166
- patchTs,
167
- replaceExtensions,
168
- syncMtsGtsSourceFiles,
169
- typescriptParser,
170
- };
167
+ export { patchTs, replaceExtensions, syncMtsGtsSourceFiles, typescriptParser };
@@ -9,24 +9,27 @@
9
9
 
10
10
  const parsedFiles = new Set();
11
11
 
12
- module.exports = {
13
- registerParsedFile(f) {
14
- parsedFiles.add(f);
15
- },
16
- preprocess: undefined,
17
- postprocess: (messages, fileName) => {
18
- const msgs = messages.flat();
19
- if (!parsedFiles.has(fileName)) {
20
- msgs[0] = msgs[0] || {
21
- message: '',
22
- };
23
- msgs[0].message += '\n';
24
- msgs[0].message +=
25
- 'To lint Gjs/Gts files please follow the setup guide at https://github.com/ember-cli/eslint-plugin-ember#gtsgjs' +
26
- '\nNote that this error can also happen if you have multiple versions of eslint-plugin-ember in your node_modules';
27
- }
28
- parsedFiles.delete(fileName); // required for tests
29
- return msgs;
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 };
@@ -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;