Skip to content
This repository has been archived by the owner on Mar 7, 2023. It is now read-only.

Commit

Permalink
chore: template-lint conversion creates absolute file path
Browse files Browse the repository at this point in the history
This is the same behavior as ESLint JSON output, and will be needed to support workspace projects.
  • Loading branch information
mdeanjones committed May 24, 2022
1 parent 03b556e commit d301ac9
Show file tree
Hide file tree
Showing 4 changed files with 9 additions and 6 deletions.
2 changes: 1 addition & 1 deletion packages/ember-cli-sonarqube/lib/gather-metrics.js
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ module.exports = async function gatherProjectMetrics(config) {
const log = logProgress('Getting TemplateLint Report', `npx ${config.tmplLintArgs.join(' ')}`);
const { stdout, exitCode } = await execa('npx', config.tmplLintArgs, execaOptions);

fs.writeFileSync(config.tmplLintOut, convertLintOut(stdout || '[]'), 'utf8');
fs.writeFileSync(config.tmplLintOut, convertLintOut(config.projectRoot, stdout || '[]'), 'utf8');

log.finish(exitCode, config.reject);
tmplLintExitCode = exitCode;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,19 +1,22 @@
const { join } = require('path');

/**
* Rewrites the JSON of ember-template-lint into ESLint formatted JSON so
* that it can be read by Sonar.
*
* @param {string} jsonString
* @param {string} projectRoot
* @param {string} jsonString
* @returns {string}
*/
module.exports = function convertTemplateLintFinding(jsonString) {
module.exports = function convertTemplateLintFinding(projectRoot, jsonString) {
const contents = JSON.parse(jsonString);
const results = [];

Object.keys(contents).forEach(function(key) {
const original = contents[key];
const updated = {};

updated.filePath = key;
updated.filePath = join(projectRoot, key);
updated.messages = [];
updated.errorCount = original.filter(item => item.severity === 2).length;
updated.warningCount = original.filter(item => item.severity === 1).length;
Expand Down
2 changes: 1 addition & 1 deletion test-packages/__fixtures__/converted-eslint-example.json
Original file line number Diff line number Diff line change
@@ -1 +1 @@
[{"filePath":"tests/dummy/app/templates/application.hbs","messages":[{"ruleId":"no-curly-component-invocation","severity":2,"message":"You are using the component {{moo}} with curly component syntax. You should use <Moo> instead. If it is actually a helper you must manually add it to the 'no-curly-component-invocation' rule configuration, e.g. `'no-curly-component-invocation': { allow: ['moo'] }`.","line":3,"column":16},{"ruleId":"no-implicit-this","severity":2,"message":"Ambiguous path 'moo' is not allowed. Use '@moo' if it is a named argument or 'this.moo' if it is a property on 'this'. If it is a helper or component that has no arguments, you must either convert it to an angle bracket invocation or manually add it to the 'no-implicit-this' rule configuration, e.g. 'no-implicit-this': { allow: ['moo'] }.","line":3,"column":18}],"errorCount":2,"warningCount":0}]
[{"filePath":"/foo/bar/tests/dummy/app/templates/application.hbs","messages":[{"ruleId":"no-curly-component-invocation","severity":2,"message":"You are using the component {{moo}} with curly component syntax. You should use <Moo> instead. If it is actually a helper you must manually add it to the 'no-curly-component-invocation' rule configuration, e.g. `'no-curly-component-invocation': { allow: ['moo'] }`.","line":3,"column":16},{"ruleId":"no-implicit-this","severity":2,"message":"Ambiguous path 'moo' is not allowed. Use '@moo' if it is a named argument or 'this.moo' if it is a property on 'this'. If it is a helper or component that has no arguments, you must either convert it to an angle bracket invocation or manually add it to the 'no-implicit-this' rule configuration, e.g. 'no-implicit-this': { allow: ['moo'] }.","line":3,"column":18}],"errorCount":2,"warningCount":0}]
2 changes: 1 addition & 1 deletion test-packages/utilities-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -171,7 +171,7 @@ describe('Utility Methods', function() {
const tmplLintJson = readFile('__fixtures__', 'template-lint-example.json');
const convertedJson = readFile('__fixtures__', 'converted-eslint-example.json');

expect(convertTemplateLint(tmplLintJson)).toEqual(convertedJson);
expect(convertTemplateLint('/foo/bar', tmplLintJson)).toEqual(convertedJson);
});
});
});

0 comments on commit d301ac9

Please sign in to comment.