eslint-plugin-ember-template-lint 0.19.0 → 0.21.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,20 +1,9 @@
1
1
  module.exports = {
2
2
  root: true,
3
3
 
4
- plugins: ['ember-template-lint'],
4
+ plugins: {
5
+ 'ember-template-lint': require('../index'),
6
+ },
5
7
 
6
- rules: {},
7
-
8
- overrides: [
9
- {
10
- files: ['**/*.hbs'],
11
- parser: require.resolve('../parser/hbs-parser'),
12
- processor: 'ember-template-lint/noop'
13
- },
14
- {
15
- files: ['**/*.gts', '**/*.gjs'],
16
- parser: 'ember-eslint-parser',
17
- processor: 'ember-template-lint/noop'
18
- },
19
- ],
8
+ rules: {}
20
9
  };
@@ -13,7 +13,8 @@ Object.entries(info.configs).forEach(([name, config]) => {
13
13
  });
14
14
  configs['config'] = {
15
15
  ...base,
16
- rules: info.configuredRules
16
+ rules: info.configuredRules,
17
+ overrides: info.configuredOverrides,
17
18
  };
18
19
 
19
20
  module.exports = configs;
@@ -0,0 +1,7 @@
1
+ module.exports = {
2
+ root: true,
3
+
4
+ plugins: ['ember-template-lint'],
5
+
6
+ rules: {}
7
+ };
@@ -0,0 +1,21 @@
1
+ const info = require('../ember-template-lint/info');
2
+ const base = require('./base');
3
+
4
+ const configs = {};
5
+
6
+ Object.entries(info.configs).forEach(([name, config]) => {
7
+ Object.entries(config.rules).forEach(([name, conf]) => {
8
+ if (typeof conf == 'boolean') {
9
+ config.rules[name] = [conf ? 'error' : 'off'];
10
+ }
11
+ });
12
+ configs[name] = {...base, rules: config.rules};
13
+ });
14
+ configs['config'] = {
15
+ ...base,
16
+ rules: info.configuredRules,
17
+ overrides: info.configuredOverrides,
18
+ };
19
+
20
+ module.exports = configs;
21
+
@@ -1,18 +1,35 @@
1
1
  const templateLintConfig = {
2
2
  rules: {},
3
3
  plugins: [],
4
+ overrides: [],
4
5
  };
5
6
 
7
+ let current = templateLintConfig;
8
+
6
9
  function registerRule(name, config) {
7
- templateLintConfig.rules[name] = Array.isArray(config) ? config[0] : config;
10
+ current.rules[name] = Array.isArray(config) ? config[0] : config;
8
11
  }
9
12
 
10
13
  function registerPlugin(name) {
11
- templateLintConfig.plugins.push(name);
14
+ current.plugins.push(name);
15
+ }
16
+
17
+ function startOverride(files) {
18
+ current = {
19
+ files,
20
+ rules: {}
21
+ };
22
+ templateLintConfig.overrides.push(current);
23
+ }
24
+
25
+ function finishOverride() {
26
+ current = templateLintConfig;
12
27
  }
13
28
 
14
29
  module.exports = {
15
30
  registerRule,
16
31
  registerPlugin,
32
+ startOverride,
33
+ finishOverride,
17
34
  templateLintConfig
18
- };
35
+ };
@@ -90,20 +90,44 @@ Object.values(configs).forEach((config) => {
90
90
  config.rules = rules;
91
91
  });
92
92
 
93
-
93
+ // enable all rules
94
94
  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
+
95
102
  Object.entries(lintConfigs.configuredRules).forEach(([name, conf]) => {
96
- if (conf.severity) {
97
- configuredRules['ember-template-lint/' + name] = configuredRules['ember-template-lint/' + name] || [];
103
+ configuredRules['ember-template-lint/' + name] = [];
104
+ configuredRules['ember-template-lint/' + name].push(conf.severity);
105
+ if (typeof conf.config !== 'boolean') {
106
+ configuredRules['ember-template-lint/' + name].push(conf.config);
107
+ }
108
+ });
109
+
110
+ const configuredOverrides = [];
111
+
112
+ for (const configuredOverride of lintConfigs.configuredOverrides) {
113
+ const configuredRules = {};
114
+ Object.entries(configuredOverride.rules).forEach(([name, conf]) => {
115
+ configuredRules['ember-template-lint/' + name] = [];
98
116
  configuredRules['ember-template-lint/' + name].push(conf.severity);
99
117
  if (typeof conf.config !== 'boolean') {
100
118
  configuredRules['ember-template-lint/' + name].push(conf.config);
101
119
  }
102
- }
103
- });
120
+ });
121
+ configuredOverrides.push({
122
+ files: configuredOverride.files,
123
+ rules: configuredRules
124
+ });
125
+ }
126
+
104
127
 
105
128
  module.exports = {
106
129
  configs: configs,
107
130
  rules: createRules(rules),
108
- configuredRules: configuredRules
131
+ configuredRules,
132
+ configuredOverrides
109
133
  };
@@ -8,5 +8,6 @@ runAsWorker(async (options) => {
8
8
  configs: lint.config.loadedConfigurations,
9
9
  rules: Object.keys(lint.config.loadedRules),
10
10
  configuredRules: lint.config.rules,
11
+ configuredOverrides: lint.config.overrides,
11
12
  };
12
13
  });
package/lib/index.js CHANGED
@@ -8,10 +8,9 @@
8
8
  // Requirements
9
9
  //------------------------------------------------------------------------------
10
10
 
11
- const configs = require('./config');
12
- const base = require('./config/base');
11
+ const configs = require('./config-legacy');
12
+ const base = require('./config-legacy/base');
13
13
  const templateRules = require('./ember-template-lint/info');
14
- const processor = require('./processor');
15
14
 
16
15
  //------------------------------------------------------------------------------
17
16
  // Plugin Definition
@@ -25,8 +24,5 @@ module.exports = {
25
24
  configs: {
26
25
  base,
27
26
  ...configs
28
- },
29
- processors: {
30
- 'noop': processor,
31
27
  }
32
28
  };
@@ -113,12 +113,23 @@ async function _applyFixes(options, results, columnOffset) {
113
113
  return currentSource;
114
114
  }
115
115
 
116
- runAsWorker(async (filename, text, options, columnOffset=0) => {
116
+ async function runTemplateLint(filename, text, options, columnOffset=0) {
117
117
  const Lint = await import('ember-template-lint');
118
118
  const lint = new Lint.default(options);
119
119
  process.env.emberTemplateLintFileName = filename;
120
120
  process.env.emberTemplateLintFixMode = false;
121
121
  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
+ ];
122
133
  let fileConfig = lint._moduleStatusCache.getConfigForFile(options);
123
134
  if (fileConfig.loadedRules['prettier']) {
124
135
  const rule = fileConfig.loadedRules['prettier'].prototype;
@@ -131,14 +142,16 @@ runAsWorker(async (filename, text, options, columnOffset=0) => {
131
142
 
132
143
  const messages = await lint.verify({
133
144
  source: text,
134
- filePath: filename.replace('.gts', '.hbs')
145
+ filePath: filename,
135
146
  });
136
147
  process.env.emberTemplateLintFixMode = true;
137
148
  await _applyFixes.call(lint,{
138
149
  source: text,
139
- filePath: filename.replace('.gts', '.hbs'),
150
+ filePath: filename,
140
151
  }, messages, columnOffset);
141
152
  return {
142
153
  messages,
143
154
  };
144
- });
155
+ }
156
+
157
+ runAsWorker(runTemplateLint);
package/lib/rules/lint.js CHANGED
@@ -1,5 +1,6 @@
1
1
  'use strict';
2
2
  const synckit = require('synckit');
3
+ const path = require('path');
3
4
  const DocumentLines = require('../utils/document');
4
5
  const { templateLintConfig } = require('../ember-template-lint/config');
5
6
 
@@ -22,7 +23,13 @@ function runTemplateLint(node, context) {
22
23
 
23
24
  try {
24
25
  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);
26
33
  const lintMessages = response.messages;
27
34
  lintMessages.forEach((m) => {
28
35
  if (m.fix) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "eslint-plugin-ember-template-lint",
3
- "version": "0.19.0",
3
+ "version": "0.21.0",
4
4
  "description": "Provide linting for ember template",
5
5
  "keywords": [
6
6
  "eslint",
@@ -10,20 +10,15 @@
10
10
  "author": "Patrick Pircher",
11
11
  "main": "lib/index.js",
12
12
  "repository": "patricklx/eslint-plugin-ember-template-lint",
13
- "scripts": {
14
- "test": "jest",
15
- "lint:js": "eslint --cache .",
16
- "test:watch": "jest --watchAll"
17
- },
18
13
  "dependencies": {
19
- "@glimmer/syntax": "^0.84.3",
20
- "@typescript-eslint/parser": "^5.59.7",
21
- "@typescript-eslint/typescript-estree": "^5.59.7",
14
+ "@glimmer/syntax": "^0.93.0",
15
+ "@typescript-eslint/parser": "^8.16.0",
16
+ "@typescript-eslint/typescript-estree": "^8.16.0",
22
17
  "ember-eslint-parser": "^0.5.6",
23
18
  "ember-template-recast": "^6.1.5",
24
19
  "ember-template-lint": "^6.0.0",
25
20
  "prettier-linter-helpers": "^1.0.0",
26
- "synckit": "^0.8.5",
21
+ "synckit": "^0.9.2",
27
22
  "typescript": "^5.0.4"
28
23
  },
29
24
  "peerDependencies": {
@@ -33,7 +28,7 @@
33
28
  "ember-template-lint-plugin-prettier": "^5.0.0",
34
29
  "eslint": "^8.41.0",
35
30
  "eslint-plugin-jest": "^27.2.1",
36
- "eslint-plugin-node": "^11.1.0",
31
+ "eslint-plugin-n": "^17.14.0",
37
32
  "jest": "^29.5.0"
38
33
  },
39
34
  "jest": {
@@ -47,5 +42,12 @@
47
42
  "license": "ISC",
48
43
  "files": [
49
44
  "lib/**/*.js"
50
- ]
51
- }
45
+ ],
46
+ "scripts": {
47
+ "test": "pnpm run /test:.*/",
48
+ "test:jest": "jest",
49
+ "lint:js": "eslint --cache lib tests",
50
+ "lint:js:fix": "eslint --cache lib tests --fix",
51
+ "test-watch": "jest --watchAll"
52
+ }
53
+ }
package/lib/processor.js DELETED
@@ -1,11 +0,0 @@
1
-
2
-
3
- module.exports = {
4
- preprocess: (text, filename) => {
5
- return [{text: text, filename}];
6
- },
7
- postprocess: (messages) => {
8
- return messages.flat();
9
- },
10
- supportsAutofix: true
11
- };