Skip to content

Commit

Permalink
fix working dir
Browse files Browse the repository at this point in the history
  • Loading branch information
patricklx committed Nov 26, 2024
1 parent 1e5cd7c commit 92c2b95
Show file tree
Hide file tree
Showing 7 changed files with 52 additions and 10 deletions.
13 changes: 10 additions & 3 deletions lib/ember-template-lint/info.js
Original file line number Diff line number Diff line change
Expand Up @@ -90,10 +90,17 @@ Object.values(configs).forEach((config) => {
config.rules = rules;
});


// enable all rules
const configuredRules = {};

for (const rule of rules) {
configuredRules['ember-template-lint/' + rule] = [];
configuredRules['ember-template-lint/' + rule].push(2);
configuredRules['ember-template-lint/' + rule].push({ __placeholder__: true });
}

Object.entries(lintConfigs.configuredRules).forEach(([name, conf]) => {
configuredRules['ember-template-lint/' + name] = configuredRules['ember-template-lint/' + name] || [];
configuredRules['ember-template-lint/' + name] = [];
configuredRules['ember-template-lint/' + name].push(conf.severity);
if (typeof conf.config !== 'boolean') {
configuredRules['ember-template-lint/' + name].push(conf.config);
Expand All @@ -105,7 +112,7 @@ const configuredOverrides = [];
for (const configuredOverride of lintConfigs.configuredOverrides) {
const configuredRules = {};
Object.entries(configuredOverride.rules).forEach(([name, conf]) => {
configuredRules['ember-template-lint/' + name] = configuredRules['ember-template-lint/' + name] || [];
configuredRules['ember-template-lint/' + name] = [];
configuredRules['ember-template-lint/' + name].push(conf.severity);
if (typeof conf.config !== 'boolean') {
configuredRules['ember-template-lint/' + name].push(conf.config);
Expand Down
11 changes: 11 additions & 0 deletions lib/rules/hbs-worker.js
Original file line number Diff line number Diff line change
Expand Up @@ -119,6 +119,17 @@ async function runTemplateLint(filename, text, options, columnOffset=0) {
process.env.emberTemplateLintFileName = filename;
process.env.emberTemplateLintFixMode = false;
await lint.loadConfig();
const processedConf = lint.config;
delete options.config;
await lint.loadConfig();
lint.config.rules = {
...lint.config.rules,
...processedConf.rules
};
lint.config.overrides = [
...lint.config.overrides,
...processedConf.overrides
];
let fileConfig = lint._moduleStatusCache.getConfigForFile(options);
if (fileConfig.loadedRules['prettier']) {
const rule = fileConfig.loadedRules['prettier'].prototype;
Expand Down
9 changes: 8 additions & 1 deletion lib/rules/lint.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
'use strict';
const synckit = require('synckit');
const path = require('path');
const DocumentLines = require('../utils/document');
const { templateLintConfig } = require('../ember-template-lint/config');

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

try {
const syncFn = synckit.createSyncFn(require.resolve('./hbs-worker'));
const response = syncFn(filename, text, { config: templateLintConfig }, columnOffset);
const config = JSON.parse(JSON.stringify(templateLintConfig));
for (const key of Object.keys(config.rules)) {
if (config.rules[key].__placeholder__) {
delete config.rules[key];
}
}
const response = syncFn(filename, text, { config, workingDir: path.dirname(filename) }, columnOffset);
const lintMessages = response.messages;
lintMessages.forEach((m) => {
if (m.fix) {
Expand Down
5 changes: 3 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,11 @@
"main": "lib/index.js",
"repository": "patricklx/eslint-plugin-ember-template-lint",
"scripts": {
"test": "jest",
"test": "pnpm run /test:.*/",
"test:jest": "jest",
"lint:js": "eslint --cache lib tests",
"lint:js:fix": "eslint --cache lib tests --fix",
"test:watch": "jest --watchAll"
"test-watch": "jest --watchAll"
},
"dependencies": {
"@glimmer/syntax": "^0.93.0",
Expand Down
20 changes: 20 additions & 0 deletions test-projects/run-lint.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
const ESLint = require('eslint');
const fs = require('fs');
const path = require('path');



async function run(filename) {
const lint = new ESLint.ESLint()
const r = await lint.lintText(fs.readFileSync(filename).toString(), {
filePath: path.resolve(filename),
});

console.log(filename)
console.log(r[0].messages);
}

run('./gjs/src/placeholer.gjs');
run('./gts/src/await.gts');
run('./gjs/src/placeholer.gjs');

2 changes: 0 additions & 2 deletions tests/lib/gts-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -37,15 +37,13 @@ function initESLint(options) {
files: ['**/*.hbs'],
parser: 'ember-template-lint/lib/parser/hbs-parser',
extends: [
'plugin:ember-template-lint/config',
'plugin:ember-template-lint/recommended',
],
},
{
files: ['**/*.gts'],
parser: 'ember-eslint-parser',
extends: [
'plugin:ember-template-lint/config',
'plugin:ember-template-lint/recommended',
],
},
Expand Down
2 changes: 0 additions & 2 deletions tests/lib/hbs-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -41,15 +41,13 @@ function initESLint(options) {
files: ['**/*.hbs'],
parser: require.resolve('../../lib/parser/hbs-parser'),
extends: [
'plugin:ember-template-lint/config',
'plugin:ember-template-lint/recommended',
],
},
{
files: ['**/*.gts'],
parser: 'ember-eslint-parser',
extends: [
'plugin:ember-template-lint/config',
'plugin:ember-template-lint/recommended',
],
},
Expand Down

0 comments on commit 92c2b95

Please sign in to comment.