Skip to content

Commit 4733e7f

Browse files
NullVoxPopuliclaude
andcommitted
Address PR review feedback
- Revert recommended.mjs to original (cannot change recommended config) - Keep noop processor unchanged; export template-lint-disable as a separate processor (ember/template-lint-disable) to avoid breaking existing gjs/gts users - Wire hbs files to use the new processor by default in base configs (hbs had no prior config, so this is additive) - Move hbs tests to a separate hbs-parser-test.js file - Update gjs template-lint-disable tests to explicitly use the new processor via initESLintWithTemplateLintDisable() Co-Authored-By: Claude Opus 4.6 (1M context) <[email protected]>
1 parent c0a657f commit 4733e7f

6 files changed

Lines changed: 166 additions & 149 deletions

File tree

lib/config-legacy/base.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ module.exports = {
2626
{
2727
files: ['**/*.hbs'],
2828
parser: 'ember-eslint-parser/hbs',
29-
processor: 'ember/noop',
29+
processor: 'ember/template-lint-disable',
3030
},
3131
],
3232
};

lib/config/base.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,6 @@ module.exports = [
2323
languageOptions: {
2424
parser: emberEslintParserHbs,
2525
},
26-
processor: 'ember/noop',
26+
processor: 'ember/template-lint-disable',
2727
},
2828
];

lib/index.js

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
'use strict';
22

33
const requireIndex = require('requireindex');
4+
const noop = require('ember-eslint-parser/noop');
45
const templateLintDisableProcessor = require('./processors/template-lint-disable');
56
const pkg = require('../package.json'); // eslint-disable-line import/extensions
67

@@ -16,6 +17,7 @@ module.exports = {
1617
},
1718
processors: {
1819
// https://eslint.org/docs/developer-guide/working-with-plugins#file-extension-named-processor
19-
noop: templateLintDisableProcessor,
20+
noop,
21+
'template-lint-disable': templateLintDisableProcessor,
2022
},
2123
};

lib/recommended.mjs

Lines changed: 0 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -3,11 +3,9 @@ import baseRules from './recommended-rules.js';
33
import gjsRules from './recommended-rules-gjs.js';
44
import gtsRules from './recommended-rules-gts.js';
55
import emberParser from 'ember-eslint-parser';
6-
import emberParserHbs from 'ember-eslint-parser/hbs';
76

87
export const plugin = emberPlugin;
98
export const parser = emberParser;
10-
export const hbsParser = emberParserHbs;
119

1210
export const base = {
1311
name: 'ember:base',
@@ -55,29 +53,14 @@ export const gts = {
5553
},
5654
};
5755

58-
export const hbs = {
59-
name: 'ember:hbs',
60-
plugins: { ember: emberPlugin },
61-
files: ['**/*.hbs'],
62-
languageOptions: {
63-
parser: emberParserHbs,
64-
},
65-
processor: 'ember/noop',
66-
rules: {
67-
...base.rules,
68-
},
69-
};
70-
7156
export default {
7257
// Helpful utility exports
7358
plugin,
7459
parser,
75-
hbsParser,
7660
// Recommended config sets
7761
configs: {
7862
base,
7963
gjs,
8064
gts,
81-
hbs,
8265
},
8366
};

tests/lib/rules-preprocessor/gjs-gts-parser-test.js

Lines changed: 34 additions & 129 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,6 @@ const { writeFileSync, readFileSync } = require('node:fs');
1313
const { join } = require('node:path');
1414

1515
const gjsGtsParser = require.resolve('ember-eslint-parser');
16-
const hbsParser = require.resolve('ember-eslint-parser/hbs');
1716

1817
/**
1918
* Helper function which creates ESLint instance with enabled/disabled autofix feature.
@@ -887,9 +886,35 @@ describe('multiple tokens in same file', () => {
887886
});
888887
});
889888

889+
function initESLintWithTemplateLintDisable() {
890+
return new ESLint({
891+
ignore: false,
892+
useEslintrc: false,
893+
plugins: { ember: plugin },
894+
overrideConfig: {
895+
root: true,
896+
env: {
897+
browser: true,
898+
},
899+
parserOptions: {
900+
ecmaVersion: 2022,
901+
sourceType: 'module',
902+
},
903+
parser: gjsGtsParser,
904+
plugins: ['ember'],
905+
processor: 'ember/template-lint-disable',
906+
rules: {
907+
'no-undef': 'error',
908+
'no-unused-vars': 'error',
909+
quotes: ['error', 'single'],
910+
},
911+
},
912+
});
913+
}
914+
890915
describe('supports template-lint-disable directive', () => {
891916
it('disables all rules on the next line with mustache comment', async () => {
892-
const eslint = initESLint();
917+
const eslint = initESLintWithTemplateLintDisable();
893918
const code = `
894919
<template>
895920
<div>
@@ -905,7 +930,7 @@ describe('supports template-lint-disable directive', () => {
905930
});
906931

907932
it('disables all rules on the next line with mustache block comment', async () => {
908-
const eslint = initESLint();
933+
const eslint = initESLintWithTemplateLintDisable();
909934
const code = `
910935
<template>
911936
<div>
@@ -920,7 +945,7 @@ describe('supports template-lint-disable directive', () => {
920945
});
921946

922947
it('disables a specific rule by eslint rule name', async () => {
923-
const eslint = initESLint();
948+
const eslint = initESLintWithTemplateLintDisable();
924949
const code = `
925950
<template>
926951
<div>
@@ -939,7 +964,7 @@ describe('supports template-lint-disable directive', () => {
939964
});
940965

941966
it('only disables the next line, not subsequent lines', async () => {
942-
const eslint = initESLint();
967+
const eslint = initESLintWithTemplateLintDisable();
943968
const code = `
944969
<template>
945970
<div>
@@ -957,7 +982,7 @@ describe('supports template-lint-disable directive', () => {
957982
});
958983

959984
it('does not suppress unrelated rules when a specific rule is named', async () => {
960-
const eslint = initESLint();
985+
const eslint = initESLintWithTemplateLintDisable();
961986
const code = `
962987
<template>
963988
<div>
@@ -974,7 +999,7 @@ describe('supports template-lint-disable directive', () => {
974999
});
9751000

9761001
it('supports template-lint rule name format (maps to ember/ prefix)', async () => {
977-
const eslint = initESLint();
1002+
const eslint = initESLintWithTemplateLintDisable();
9781003
const code = `
9791004
<template>
9801005
<div>
@@ -989,7 +1014,7 @@ describe('supports template-lint-disable directive', () => {
9891014
});
9901015

9911016
it('supports multiple rule names', async () => {
992-
const eslint = initESLint();
1017+
const eslint = initESLintWithTemplateLintDisable();
9931018
const code = `
9941019
<template>
9951020
<div>
@@ -1004,7 +1029,7 @@ describe('supports template-lint-disable directive', () => {
10041029
});
10051030

10061031
it('works with multiple disable comments in the same file', async () => {
1007-
const eslint = initESLint();
1032+
const eslint = initESLintWithTemplateLintDisable();
10081033
const code = `
10091034
<template>
10101035
<div>
@@ -1021,123 +1046,3 @@ describe('supports template-lint-disable directive', () => {
10211046
});
10221047
});
10231048

1024-
function initHbsESLint() {
1025-
return new ESLint({
1026-
ignore: false,
1027-
useEslintrc: false,
1028-
plugins: { ember: plugin },
1029-
overrideConfig: {
1030-
root: true,
1031-
parserOptions: {
1032-
ecmaVersion: 2022,
1033-
sourceType: 'module',
1034-
},
1035-
plugins: ['ember'],
1036-
overrides: [
1037-
{
1038-
files: ['**/*.hbs'],
1039-
parser: hbsParser,
1040-
processor: 'ember/noop',
1041-
rules: {
1042-
'ember/template-no-bare-strings': 'error',
1043-
},
1044-
},
1045-
],
1046-
},
1047-
});
1048-
}
1049-
1050-
describe('supports template-lint-disable directive in hbs files', () => {
1051-
it('disables all rules on the next line with mustache comment', async () => {
1052-
const eslint = initHbsESLint();
1053-
const code = `<div>
1054-
{{! template-lint-disable }}
1055-
Hello world
1056-
</div>`;
1057-
const results = await eslint.lintText(code, { filePath: 'my-template.hbs' });
1058-
const resultErrors = results.flatMap((result) => result.messages);
1059-
expect(resultErrors).toHaveLength(0);
1060-
});
1061-
1062-
it('disables all rules on the next line with mustache block comment', async () => {
1063-
const eslint = initHbsESLint();
1064-
const code = `<div>
1065-
{{!-- template-lint-disable --}}
1066-
Hello world
1067-
</div>`;
1068-
const results = await eslint.lintText(code, { filePath: 'my-template.hbs' });
1069-
const resultErrors = results.flatMap((result) => result.messages);
1070-
expect(resultErrors).toHaveLength(0);
1071-
});
1072-
1073-
it('only disables the next line, not subsequent lines', async () => {
1074-
const eslint = initHbsESLint();
1075-
const code = `{{! template-lint-disable }}
1076-
<div>Hello world</div>
1077-
<div>Bare string here too</div>`;
1078-
const results = await eslint.lintText(code, { filePath: 'my-template.hbs' });
1079-
const resultErrors = results.flatMap((result) => result.messages);
1080-
// Line 2 "Hello world" suppressed, but line 3 "Bare string here too" should still error
1081-
expect(resultErrors).toHaveLength(1);
1082-
expect(resultErrors[0].line).toBe(3);
1083-
});
1084-
1085-
it('disables a specific rule by name', async () => {
1086-
const eslint = initHbsESLint();
1087-
const code = `<div>
1088-
{{! template-lint-disable ember/template-no-bare-strings }}
1089-
Hello world
1090-
</div>`;
1091-
const results = await eslint.lintText(code, { filePath: 'my-template.hbs' });
1092-
const resultErrors = results.flatMap((result) => result.messages);
1093-
expect(resultErrors).toHaveLength(0);
1094-
});
1095-
1096-
it('supports template-lint rule name format (maps to ember/ prefix)', async () => {
1097-
const eslint = initHbsESLint();
1098-
const code = `<div>
1099-
{{! template-lint-disable no-bare-strings }}
1100-
Hello world
1101-
</div>`;
1102-
const results = await eslint.lintText(code, { filePath: 'my-template.hbs' });
1103-
const resultErrors = results.flatMap((result) => result.messages);
1104-
expect(resultErrors).toHaveLength(0);
1105-
});
1106-
1107-
it('does not suppress unrelated rules when a specific rule is named', async () => {
1108-
const eslint = initHbsESLint();
1109-
const code = `<div>
1110-
{{! template-lint-disable ember/template-no-html-comments }}
1111-
Hello world
1112-
</div>`;
1113-
const results = await eslint.lintText(code, { filePath: 'my-template.hbs' });
1114-
const resultErrors = results.flatMap((result) => result.messages);
1115-
// no-bare-strings should still fire since we only disabled no-html-comments
1116-
expect(resultErrors).toHaveLength(1);
1117-
expect(resultErrors[0].ruleId).toBe('ember/template-no-bare-strings');
1118-
});
1119-
1120-
it('works with multiple disable comments in the same file', async () => {
1121-
const eslint = initHbsESLint();
1122-
const code = `<div>
1123-
{{! template-lint-disable }}
1124-
Hello world
1125-
{{! template-lint-disable }}
1126-
Another bare string
1127-
</div>`;
1128-
const results = await eslint.lintText(code, { filePath: 'my-template.hbs' });
1129-
const resultErrors = results.flatMap((result) => result.messages);
1130-
expect(resultErrors).toHaveLength(0);
1131-
});
1132-
1133-
it('bare strings without disable comment still trigger errors', async () => {
1134-
const eslint = initHbsESLint();
1135-
const code = `<div>
1136-
Hello world
1137-
</div>`;
1138-
const results = await eslint.lintText(code, { filePath: 'my-template.hbs' });
1139-
const resultErrors = results.flatMap((result) => result.messages);
1140-
expect(resultErrors).toHaveLength(1);
1141-
expect(resultErrors[0].ruleId).toBe('ember/template-no-bare-strings');
1142-
});
1143-
});

0 commit comments

Comments
 (0)