Skip to content

Commit 92c2b95

Browse files
committed
fix working dir
1 parent 1e5cd7c commit 92c2b95

File tree

7 files changed

+52
-10
lines changed

7 files changed

+52
-10
lines changed

lib/ember-template-lint/info.js

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -90,10 +90,17 @@ Object.values(configs).forEach((config) => {
9090
config.rules = rules;
9191
});
9292

93-
93+
// enable all rules
9494
const configuredRules = {};
95+
96+
for (const rule of rules) {
97+
configuredRules['ember-template-lint/' + rule] = [];
98+
configuredRules['ember-template-lint/' + rule].push(2);
99+
configuredRules['ember-template-lint/' + rule].push({ __placeholder__: true });
100+
}
101+
95102
Object.entries(lintConfigs.configuredRules).forEach(([name, conf]) => {
96-
configuredRules['ember-template-lint/' + name] = configuredRules['ember-template-lint/' + name] || [];
103+
configuredRules['ember-template-lint/' + name] = [];
97104
configuredRules['ember-template-lint/' + name].push(conf.severity);
98105
if (typeof conf.config !== 'boolean') {
99106
configuredRules['ember-template-lint/' + name].push(conf.config);
@@ -105,7 +112,7 @@ const configuredOverrides = [];
105112
for (const configuredOverride of lintConfigs.configuredOverrides) {
106113
const configuredRules = {};
107114
Object.entries(configuredOverride.rules).forEach(([name, conf]) => {
108-
configuredRules['ember-template-lint/' + name] = configuredRules['ember-template-lint/' + name] || [];
115+
configuredRules['ember-template-lint/' + name] = [];
109116
configuredRules['ember-template-lint/' + name].push(conf.severity);
110117
if (typeof conf.config !== 'boolean') {
111118
configuredRules['ember-template-lint/' + name].push(conf.config);

lib/rules/hbs-worker.js

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -119,6 +119,17 @@ async function runTemplateLint(filename, text, options, columnOffset=0) {
119119
process.env.emberTemplateLintFileName = filename;
120120
process.env.emberTemplateLintFixMode = false;
121121
await lint.loadConfig();
122+
const processedConf = lint.config;
123+
delete options.config;
124+
await lint.loadConfig();
125+
lint.config.rules = {
126+
...lint.config.rules,
127+
...processedConf.rules
128+
};
129+
lint.config.overrides = [
130+
...lint.config.overrides,
131+
...processedConf.overrides
132+
];
122133
let fileConfig = lint._moduleStatusCache.getConfigForFile(options);
123134
if (fileConfig.loadedRules['prettier']) {
124135
const rule = fileConfig.loadedRules['prettier'].prototype;

lib/rules/lint.js

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
'use strict';
22
const synckit = require('synckit');
3+
const path = require('path');
34
const DocumentLines = require('../utils/document');
45
const { templateLintConfig } = require('../ember-template-lint/config');
56

@@ -22,7 +23,13 @@ function runTemplateLint(node, context) {
2223

2324
try {
2425
const syncFn = synckit.createSyncFn(require.resolve('./hbs-worker'));
25-
const response = syncFn(filename, text, { config: templateLintConfig }, columnOffset);
26+
const config = JSON.parse(JSON.stringify(templateLintConfig));
27+
for (const key of Object.keys(config.rules)) {
28+
if (config.rules[key].__placeholder__) {
29+
delete config.rules[key];
30+
}
31+
}
32+
const response = syncFn(filename, text, { config, workingDir: path.dirname(filename) }, columnOffset);
2633
const lintMessages = response.messages;
2734
lintMessages.forEach((m) => {
2835
if (m.fix) {

package.json

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,10 +11,11 @@
1111
"main": "lib/index.js",
1212
"repository": "patricklx/eslint-plugin-ember-template-lint",
1313
"scripts": {
14-
"test": "jest",
14+
"test": "pnpm run /test:.*/",
15+
"test:jest": "jest",
1516
"lint:js": "eslint --cache lib tests",
1617
"lint:js:fix": "eslint --cache lib tests --fix",
17-
"test:watch": "jest --watchAll"
18+
"test-watch": "jest --watchAll"
1819
},
1920
"dependencies": {
2021
"@glimmer/syntax": "^0.93.0",

test-projects/run-lint.js

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
const ESLint = require('eslint');
2+
const fs = require('fs');
3+
const path = require('path');
4+
5+
6+
7+
async function run(filename) {
8+
const lint = new ESLint.ESLint()
9+
const r = await lint.lintText(fs.readFileSync(filename).toString(), {
10+
filePath: path.resolve(filename),
11+
});
12+
13+
console.log(filename)
14+
console.log(r[0].messages);
15+
}
16+
17+
run('./gjs/src/placeholer.gjs');
18+
run('./gts/src/await.gts');
19+
run('./gjs/src/placeholer.gjs');
20+

tests/lib/gts-test.js

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -37,15 +37,13 @@ function initESLint(options) {
3737
files: ['**/*.hbs'],
3838
parser: 'ember-template-lint/lib/parser/hbs-parser',
3939
extends: [
40-
'plugin:ember-template-lint/config',
4140
'plugin:ember-template-lint/recommended',
4241
],
4342
},
4443
{
4544
files: ['**/*.gts'],
4645
parser: 'ember-eslint-parser',
4746
extends: [
48-
'plugin:ember-template-lint/config',
4947
'plugin:ember-template-lint/recommended',
5048
],
5149
},

tests/lib/hbs-test.js

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -41,15 +41,13 @@ function initESLint(options) {
4141
files: ['**/*.hbs'],
4242
parser: require.resolve('../../lib/parser/hbs-parser'),
4343
extends: [
44-
'plugin:ember-template-lint/config',
4544
'plugin:ember-template-lint/recommended',
4645
],
4746
},
4847
{
4948
files: ['**/*.gts'],
5049
parser: 'ember-eslint-parser',
5150
extends: [
52-
'plugin:ember-template-lint/config',
5351
'plugin:ember-template-lint/recommended',
5452
],
5553
},

0 commit comments

Comments
 (0)