ember-eslint-parser 0.1.1 → 0.2.1
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/README.md +32 -0
- package/package.json +5 -3
- package/src/parser/transforms.js +17 -5
- package/src/preprocessor/noop.js +8 -11
package/README.md
CHANGED
|
@@ -1 +1,33 @@
|
|
|
1
1
|
# ember-eslint-parser
|
|
2
|
+
|
|
3
|
+
This is the eslint parser for ember's gjs and gts files (using `<template>`).
|
|
4
|
+
|
|
5
|
+
It is meant to be used with [eslint-plugin-ember](https://github.com/ember-cli/eslint-plugin-ember), which provides nice defaults for all the different file types in ember projects.
|
|
6
|
+
|
|
7
|
+
It's recommended to only use _overrides_ when defining your eslint config, so using this parser would look like this:
|
|
8
|
+
```js
|
|
9
|
+
{
|
|
10
|
+
files: ['**/*.gjs'],
|
|
11
|
+
parser: 'ember-eslint-parser',
|
|
12
|
+
plugins: ['ember'],
|
|
13
|
+
extends: [
|
|
14
|
+
'eslint:recommended',
|
|
15
|
+
'plugin:ember/recommended',
|
|
16
|
+
'plugin:ember/recommended-gjs',
|
|
17
|
+
],
|
|
18
|
+
},
|
|
19
|
+
{
|
|
20
|
+
files: ['**/*.gts'],
|
|
21
|
+
parser: 'ember-eslint-parser',
|
|
22
|
+
plugins: ['ember'],
|
|
23
|
+
extends: [
|
|
24
|
+
'eslint:recommended',
|
|
25
|
+
'plugin:ember/recommended',
|
|
26
|
+
'plugin:ember/recommended-gts',
|
|
27
|
+
],
|
|
28
|
+
},
|
|
29
|
+
```
|
|
30
|
+
|
|
31
|
+
## Support
|
|
32
|
+
|
|
33
|
+
eslint-plugin-ember is the primary consumer of this parser library, so SemVer _may_ not be respected for other consumers.
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "ember-eslint-parser",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.2.1",
|
|
4
4
|
"description": "",
|
|
5
5
|
"keywords": [],
|
|
6
6
|
"repository": {
|
|
@@ -10,7 +10,8 @@
|
|
|
10
10
|
"license": "ISC",
|
|
11
11
|
"author": "",
|
|
12
12
|
"exports": {
|
|
13
|
-
".": "./src/parser/gjs-gts-parser.js"
|
|
13
|
+
".": "./src/parser/gjs-gts-parser.js",
|
|
14
|
+
"./noop": "./src/preprocessor/noop.js"
|
|
14
15
|
},
|
|
15
16
|
"main": "src/parser/gjs-gts-parser.js",
|
|
16
17
|
"files": [
|
|
@@ -27,6 +28,8 @@
|
|
|
27
28
|
"eslint-plugin-n": "^16.4.0",
|
|
28
29
|
"eslint-plugin-prettier": "^5.0.1",
|
|
29
30
|
"eslint-plugin-promise": "^6.0.0",
|
|
31
|
+
"execa": "^8.0.1",
|
|
32
|
+
"fs-extra": "^11.2.0",
|
|
30
33
|
"jest": "^29.7.0",
|
|
31
34
|
"prettier": "^3.1.1",
|
|
32
35
|
"publint": "^0.2.6",
|
|
@@ -50,7 +53,6 @@
|
|
|
50
53
|
"typescript": "^5.3.3"
|
|
51
54
|
},
|
|
52
55
|
"scripts": {
|
|
53
|
-
"test": "echo \"Error: no test specified\" && exit 1",
|
|
54
56
|
"lint": "concurrently \"npm:lint:*(!fix)\" --names \"lint:\"",
|
|
55
57
|
"lint:js": "eslint .",
|
|
56
58
|
"lint:package": "pnpm publint",
|
package/src/parser/transforms.js
CHANGED
|
@@ -48,6 +48,7 @@ function findVarInParentScopes(scopeManager, nodePath, name) {
|
|
|
48
48
|
if (!scope) {
|
|
49
49
|
return { scope: currentScope };
|
|
50
50
|
}
|
|
51
|
+
|
|
51
52
|
return { scope: currentScope, variable: scope.set.get(name) };
|
|
52
53
|
}
|
|
53
54
|
|
|
@@ -268,6 +269,10 @@ module.exports.preprocessGlimmerTemplates = function preprocessGlimmerTemplates(
|
|
|
268
269
|
for (const part of n.tag.split('.')) {
|
|
269
270
|
const regex = new RegExp(`\\b${part}\\b`);
|
|
270
271
|
const match = codeSlice.match(regex);
|
|
272
|
+
|
|
273
|
+
// named-blocks are not ElementNodes
|
|
274
|
+
if (!match && part.startsWith(':')) continue;
|
|
275
|
+
|
|
271
276
|
const range = [start + match.index, 0];
|
|
272
277
|
range[1] = range[0] + part.length;
|
|
273
278
|
codeSlice = code.slice(range[1], n.range[1]);
|
|
@@ -421,14 +426,21 @@ module.exports.convertAst = function convertAst(result, preprocessedResult, visi
|
|
|
421
426
|
// always reference first part of tag name, this also has the advantage
|
|
422
427
|
// that errors regarding this tag will only mark the tag name instead of
|
|
423
428
|
// the whole tag + children
|
|
424
|
-
|
|
429
|
+
//
|
|
430
|
+
// However, with plain <footer> type nodes, there will be no "parts"
|
|
431
|
+
const n = node.parts?.[0] ?? node;
|
|
432
|
+
|
|
433
|
+
const name = n?.name ?? n.tag;
|
|
434
|
+
|
|
435
|
+
if (htmlTags.includes(name)) {
|
|
436
|
+
return null;
|
|
437
|
+
}
|
|
438
|
+
|
|
425
439
|
const { scope, variable } = findVarInParentScopes(result.scopeManager, path, n.name) || {};
|
|
426
440
|
if (
|
|
427
441
|
scope &&
|
|
428
|
-
(
|
|
429
|
-
|
|
430
|
-
node.name.includes('.') ||
|
|
431
|
-
!htmlTags.includes(node.name))
|
|
442
|
+
!name.startsWith(':') &&
|
|
443
|
+
(variable || isUpperCase(n.name[0]) || name.includes('.') || !htmlTags.includes(name))
|
|
432
444
|
) {
|
|
433
445
|
registerNodeInScope(n, scope, variable);
|
|
434
446
|
}
|
package/src/preprocessor/noop.js
CHANGED
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
* this preprocessor is setup by our recommended rules for gjs/gts, so it will always be called for it
|
|
4
4
|
* the flow is the following:
|
|
5
5
|
* 1. gjs/gts files goes through our parses, which calls registerParsedFile, if its not correctly setup, registerParsedFile will not be called
|
|
6
|
-
* 2. postprocess checks if the file is registered and if not throws an error
|
|
6
|
+
* 2. postprocess checks if the file is registered and if not throws an error
|
|
7
7
|
*
|
|
8
8
|
*/
|
|
9
9
|
|
|
@@ -16,16 +16,13 @@ module.exports = {
|
|
|
16
16
|
preprocess: null,
|
|
17
17
|
postprocess: (messages, fileName) => {
|
|
18
18
|
const msgs = messages.flat();
|
|
19
|
-
if (
|
|
20
|
-
msgs
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
msgs[0].message +=
|
|
27
|
-
'To lint Gjs/Gts files please follow the setup guide at https://github.com/ember-cli/eslint-plugin-ember#gtsgjs';
|
|
28
|
-
}
|
|
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';
|
|
29
26
|
}
|
|
30
27
|
parsedFiles.delete(fileName); // required for tests
|
|
31
28
|
return msgs;
|