Skip to content

Commit

Permalink
feat: better CLI defaults - autofix, logging, extensions
Browse files Browse the repository at this point in the history
Signed-off-by: Charlike Mike Reagent <olsten.larck@gmail.com>
  • Loading branch information
Charlike Mike Reagent committed Jul 7, 2018
1 parent f2cad86 commit 64457b9
Show file tree
Hide file tree
Showing 4 changed files with 266 additions and 120 deletions.
11 changes: 6 additions & 5 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,9 @@
"version": "0.0.0-new-release-placeholder",
"description": "Zero-config linting, powered by few amazing unicorns, AirBnB & Prettier.",
"main": "src/",
"module": "src/index.mjs",
"scripts": {
"lint": "xaxa",
"lint": "node src/cli.js",
"test": "node test",
"precommit": "yarn lint && yarn test && yarn gitadd",
"gitadd": "git status --porcelain && git add -A",
Expand All @@ -28,18 +29,18 @@
"eslint-plugin-prettier": "^2.6.0",
"eslint-plugin-react": "^7.8.2",
"eslint-plugin-unicorn": "^4.0.3",
"esm": "^3.0.63",
"mri": "^1.1.1",
"prettier": "^1.12.1",
"prettier-eslint": "^8.8.1"
},
"devDependencies": {
"asia": "*",
"gitcommit": "^1.0.7",
"new-release": "^4.0.1",
"xaxa": "*"
"mukla": "^0.4.9",
"new-release": "^4.0.1"
},
"eslintConfig": {
"extends": "./node_modules/xaxa/src/index.js"
"extends": "./src/index.js"
},
"publishConfig": {
"access": "public"
Expand Down
36 changes: 31 additions & 5 deletions src/cli.js
Original file line number Diff line number Diff line change
@@ -1,17 +1,24 @@
#!/usr/bin/env node

const proc = require('process');
const path = require('path');
const mri = require('mri');
const arrayify = require('arrayify');
const { CLIEngine } = require('eslint');

const argv = mri(process.argv.slice(2), {
const argv = mri(proc.argv.slice(2), {
default: {
fix: true,
exit: true,
warnings: false,
reporter: 'codeframe',
input: ['src', 'test'],
extensions: ['.mjs', '.js'],
},
array: ['extensions'],
alias: {
x: 'extensions',
w: 'warnings',
r: 'require',
R: 'reporter',
},
Expand All @@ -22,19 +29,38 @@ if (argv.require) {
require(argv.require);
}

const filename = (proc.mainModule && proc.mainModule.filename) || __filename;
const dirname = path.dirname(filename);

// TODO: expose as API
const cli = new CLIEngine({
useEslintrc: false,
cache: true,
fix: argv.fix,
reportUnusedDisableDirectives: true,
configFile: path.join(__dirname, 'index.js'),
extensions: ['.mjs', '.js', 'jsx'],
configFile: path.join(dirname, 'index.js'),
extensions: arrayify(argv.extensions),
ignore: argv.ignore,
});

const patterns = arrayify(argv._.length ? argv._ : argv.input).filter(Boolean);

const report = cli.executeOnFiles(patterns);

if (report.results.length === 0) {
console.error('Error: no files to lint. Try adding "-x .mjs -x .js" flags');
proc.exit(1);
}

if (report.results.length > 0 && report.warningCount > 0 && !argv.warnings) {
CLIEngine.outputFixes(report);
console.log(
`No linting errors found, but there are ${report.warningCount} warnings!`,
);
console.log('Try running `xaxa --warnings` to see them.');
proc.exit(0);
}

const format = cli.getFormatter(argv.reporter);

CLIEngine.outputFixes(report);
Expand All @@ -45,8 +71,8 @@ const output = argv.warnings

if (report.errorCount && !!argv.exit) {
console.error(output);
process.exit(1);
proc.exit(1);
} else {
console.log(output);
process.exit(0);
proc.exit(0);
}
6 changes: 3 additions & 3 deletions test/index.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
const test = require('asia');
const test = require('mukla');

test('xaxa', (t) => {
test('xaxa', (done) => {
console.log('yeah');
t.pass();
done();
});
Loading

0 comments on commit 64457b9

Please sign in to comment.