Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improve lint script #426

Merged
merged 15 commits into from Nov 2, 2019
35 changes: 26 additions & 9 deletions test/lint/lint.js
Expand Up @@ -3,16 +3,13 @@
const {CLIEngine} = require('eslint');
const unicorn = require('../..');

const {configs: {recommended}} = unicorn;
const {rules} = recommended;
const {recommended} = unicorn.configs;
const files = [process.argv[2] || '.'];
const fix = process.argv.includes('--fix');

const cli = new CLIEngine({
...recommended,
baseConfig: recommended,
rules: {
...rules,

// TODO: remove this override, when #391 is fixed
'unicorn/consistent-function-scoping': 'off'
},
Expand All @@ -22,14 +19,34 @@ const cli = new CLIEngine({

cli.addPlugin('eslint-plugin-unicorn', unicorn);

// Find a way to make sure rules are loaded from codebase
fisker marked this conversation as resolved.
Show resolved Hide resolved

const report = cli.executeOnFiles(files);

if (fix) {
const {errorCount, warningCount, fixableErrorCount, fixableWarningCount} = report;

const hasFixable = fixableErrorCount || fixableWarningCount;

if (fix && hasFixable) {
CLIEngine.outputFixes(report);
}

const formatter = cli.getFormatter();
if (errorCount || warningCount) {
const formatter = cli.getFormatter();
console.log(formatter(report.results));

console.log(formatter(report.results));
console.log();
console.log('Some tests have failed, you need fix them and run `npm run lint <file>` to check again.');
fisker marked this conversation as resolved.
Show resolved Hide resolved

if (hasFixable) {
console.log();
console.log('You may also want run `npm run lint <file> --fix` to fix fixable problems.');
}

console.log();
console.log('* If you\'re making a new rule, you can fix this later. *');
} else {
console.log('All tests have passed.');
}

process.exit(report.errorCount);
process.exit(errorCount);