Skip to content

Commit

Permalink
add autofix option
Browse files Browse the repository at this point in the history
  • Loading branch information
Dauta committed Feb 8, 2022
1 parent 0fb69ea commit 616b698
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 15 deletions.
16 changes: 12 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,14 +7,22 @@ All-in-one code linter and formatter for TypeScript and JavaScript
- `npm install @dauta/uniform` or `yarn add @dauta/uniform`
- `npx uniform` or `yarn uniform`

## 🤔 What will this do?
_Note:_ You _might_ need to restart ESLint server in your IDE for the config files to get picked up.

Installing the package will install eslint and prettier as a dependency of your project, along with several plugins and configuration files.
## 🤔 What will this do?

Running the `uniform` script, will copy the predefined configuration files into the root of your project. This will allow your IDE (or whatever extension you're using to run eslint) to read the correct configurations and give realtime feedback on your code.
Installing the package will install eslint and prettier as a dependency of your project, along with several plugins and configuration files.

Running the `uniform` script, will copy the predefined configuration files into the root of your project. This will allow your IDE (or whatever extension you're using to run eslint) to read the correct configurations and give realtime feedback on your code.

## 💻 CLI

To lint your code manually, run `npx uniform lint` or `yarn uniform lint`.
To auto-fix some issues, add the `--fix` flag to the above command.
That's it :)

## 🤩 Recommended Setup

We recommend running uniform with [ESLint](https://marketplace.visualstudio.com/items?itemName=dbaeumer.vscode-eslint) extension and setting up the "format on save" option.

✨ Enjoy!
✨ Enjoy!
8 changes: 4 additions & 4 deletions index.js
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
#!/usr/bin/env node
const [arg] = process.argv.slice(2);
const [command, flag] = process.argv.slice(2);

if (arg === 'lint') {
if (command === 'lint') {
const fix = flag === '--fix';
const { lint } = require('./src/lint');
lint();

lint(fix);
return;
}

Expand Down
20 changes: 13 additions & 7 deletions src/lint.js
Original file line number Diff line number Diff line change
@@ -1,22 +1,22 @@
const { ESLint } = require('eslint');

async function lint() {
async function lint(fix) {
const linter = new ESLint({
errorOnUnmatchedPattern: false,
extensions: ['ts', 'js', 'mjs', 'jsx', 'tsx'],
fix,
});

const results = await linter.lintFiles('.');

if (fix) {
await ESLint.outputFixes(results);
}

const totalIssues = results.reduce((acc, curr) => {
return acc + curr.messages.length;
}, 0);

console.log(
`Linted ${results.length} ${
results.length === 1 ? 'file' : 'files'
}. Found ${totalIssues} ${totalIssues === 1 ? 'issue' : 'issues'}.`
);

if (totalIssues === 0) return;

results.forEach((result) => {
Expand All @@ -28,6 +28,12 @@ async function lint() {
console.log(`\tat line ${message.line}: ${message.message}\n`);
});
});

console.log(
`Linted ${results.length} ${
results.length === 1 ? 'file' : 'files'
}. Found ${totalIssues} ${totalIssues === 1 ? 'issue' : 'issues'}.`
);
}

module.exports = { lint };

0 comments on commit 616b698

Please sign in to comment.