Skip to content

Commit

Permalink
fix: lint typescript files
Browse files Browse the repository at this point in the history
  • Loading branch information
Marsup committed Jul 27, 2024
1 parent 7ea1b19 commit c306580
Show file tree
Hide file tree
Showing 6 changed files with 40 additions and 0 deletions.
4 changes: 4 additions & 0 deletions lib/linter/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,10 @@ exports.lint = async function () {
}
}

if (configuration.typescript) {
delete configuration.typescript;
}

let results;
try {
const eslint = new Eslint.ESLint(configuration);
Expand Down
4 changes: 4 additions & 0 deletions lib/modules/lint.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,10 @@ exports.lint = function (settings) {

linterOptions.fix = settings['lint-fix'];

if (settings.typescript) {
linterOptions.typescript = true;
}

const child = ChildProcess.fork(linterPath, [JSON.stringify(linterOptions)], { cwd: settings.lintingPath });
child.once('message', (message) => {

Expand Down
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@
"@hapi/code": "^9.0.0",
"@hapi/somever": "^4.0.0",
"@types/node": "^18.11.17",
"@typescript-eslint/parser": "^5.62.0",
"cpr": "3.x.x",
"lab-event-reporter": "1.x.x",
"semver": "7.x.x",
Expand Down
5 changes: 5 additions & 0 deletions test/lint/eslint/typescript/.eslintrc.cjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
'use strict';

module.exports = {
parser: '@typescript-eslint/parser'
};
7 changes: 7 additions & 0 deletions test/lint/eslint/typescript/fail.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
const internals = {};


export const method = function (value) {

return value
};
19 changes: 19 additions & 0 deletions test/linters.js
Original file line number Diff line number Diff line change
Expand Up @@ -118,6 +118,25 @@ describe('Linters - eslint', () => {
]);
});

it('should lint typescript files in a folder', async () => {

const path = Path.join(__dirname, 'lint', 'eslint', 'typescript');
const result = await Linters.lint({ lintingPath: path, linter: 'eslint', typescript: true });

expect(result).to.include('lint');

const eslintResults = result.lint;
expect(eslintResults).to.have.length(2);

const checkedFile = eslintResults.find(({ filename }) => filename.endsWith('.ts'));
expect(checkedFile).to.include({ filename: Path.join(path, 'fail.ts') });
expect(checkedFile.errors).to.include([
{ line: 1, severity: 'ERROR', message: `strict - Use the global form of 'use strict'.` },
{ line: 6, severity: 'ERROR', message: 'indent - Expected indentation of 4 spaces but found 1 tab.' },
{ line: 6, severity: 'ERROR', message: 'semi - Missing semicolon.' }
]);
});

it('displays success message if no issues found', async () => {

const path = Path.join(__dirname, 'lint', 'eslint', 'clean');
Expand Down

0 comments on commit c306580

Please sign in to comment.