Skip to content

Commit

Permalink
update for next major release
Browse files Browse the repository at this point in the history
- Update to ESLint 8.
- Update other dependencies.
- Add/remove rules.
- General refactor of code and output format.
- Move CI to GitHub Actions.
  • Loading branch information
cjihrig committed Sep 12, 2021
1 parent 7ddcc68 commit beaf30a
Show file tree
Hide file tree
Showing 10 changed files with 101 additions and 267 deletions.
15 changes: 6 additions & 9 deletions .eslintrc.js
Expand Up @@ -4,12 +4,9 @@ module.exports = {
root: true,
env: {
browser: false,
es6: true,
es2021: true,
node: true
},
parserOptions: {
ecmaVersion: 2020
},
reportUnusedDisableDirectives: true,
rules: {
'accessor-pairs': 'error',
Expand All @@ -34,15 +31,13 @@ module.exports = {
'func-call-spacing': ['error', 'never'],
'generator-star-spacing': ['error', { 'before': true, 'after': false }],
'getter-return': 'error',
'handle-callback-err': ['error', '^(err|error)$' ],
'indent': ['error', 2, { 'SwitchCase': 1 }],
'key-spacing': ['error', { 'beforeColon': false, 'afterColon': true }],
'keyword-spacing': ['error', { 'before': true, 'after': true }],
'new-cap': ['error', { 'newIsCap': true, 'capIsNew': false }],
'new-parens': 'error',
'no-array-constructor': 'error',
'no-async-promise-executor': 'error',
'no-buffer-constructor': 'error',
'no-caller': 'error',
'no-class-assign': 'error',
'no-compare-neg-zero': 'error',
Expand Down Expand Up @@ -81,6 +76,7 @@ module.exports = {
'no-label-var': 'error',
'no-labels': ['error', { 'allowLoop': true, 'allowSwitch': true }],
'no-lone-blocks': 'error',
'no-loss-of-precision': 'error',
'no-misleading-character-class': 'error',
'no-mixed-spaces-and-tabs': 'error',
'no-multi-spaces': ['error', { 'ignoreEOLComments': true }],
Expand All @@ -90,7 +86,6 @@ module.exports = {
'no-new-func': 'error',
'no-new-object': 'error',
'no-new-symbol': 'error',
'no-new-require': 'error',
'no-new-wrappers': 'error',
'no-obj-calls': 'error',
'no-octal': 'error',
Expand All @@ -100,7 +95,6 @@ module.exports = {
'no-regex-spaces': 'error',
'no-restricted-exports': 'error',
'no-return-assign': 'error',
'no-return-await': 'error',
'no-self-assign': 'error',
'no-self-compare': 'error',
'no-sequences': 'error',
Expand All @@ -116,8 +110,11 @@ module.exports = {
'no-unexpected-multiline': 'error',
'no-unneeded-ternary': ['error', { 'defaultAssignment': false }],
'no-unreachable': 'error',
'no-unreachable-loop': 'error',
'no-unsafe-finally': 'error',
'no-unsafe-negation': 'error',
'no-unsafe-optional-chaining': 'error',
'no-unused-expressions': 'error',
'no-unused-vars': ['error', { 'vars': 'all', 'args': 'none' }],
'no-use-before-define': ['error', 'nofunc'],
'no-useless-backreference': 'error',
Expand Down Expand Up @@ -149,7 +146,7 @@ module.exports = {
'semi': ['error', 'always'],
'semi-spacing': ['error', { 'before': false, 'after': true }],
'space-before-blocks': ['error', 'always'],
'space-before-function-paren': ['error', 'always'],
'space-before-function-paren': ['error', { 'anonymous': 'never', 'named': 'never', 'asyncArrow': 'always' }],
'space-in-parens': ['error', 'never'],
'space-infix-ops': 'error',
'space-unary-ops': ['error', { 'words': true, 'nonwords': false }],
Expand Down
28 changes: 28 additions & 0 deletions .github/workflows/CI.yml
@@ -0,0 +1,28 @@
name: belly-button CI

on:
push:
branches: [main]
pull_request:
branches: [main]

jobs:
build:

runs-on: ${{ matrix.os }}

strategy:
matrix:
node-version: [12.x, 14.x, 16.x]
os: [ubuntu-latest, macos-latest, windows-latest]

steps:
- uses: actions/checkout@v2
- name: Use Node.js ${{ matrix.node-version }}
uses: actions/setup-node@v1
with:
node-version: ${{ matrix.node-version }}
- run: npm install
- run: npm test
env:
CI: true
6 changes: 0 additions & 6 deletions .travis.yml

This file was deleted.

2 changes: 1 addition & 1 deletion LICENSE
@@ -1,6 +1,6 @@
The MIT License (MIT)

Copyright (c) 2015 Colin J. Ihrig
Copyright (c) 2015-2021 Colin J. Ihrig

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
Expand Down
14 changes: 9 additions & 5 deletions bin/belly-button.js
@@ -1,12 +1,16 @@
#!/usr/bin/env node
'use strict';

require('../lib/cli').run(process.argv, (err, output, code) => {
if (err) {
async function main() {
try {
const [output, code] = await require('../lib/cli').run(process.argv);

console.log(output);
process.exit(code);
} catch (err) {
console.error(err.message);
process.exit(1);
}
}

console.log(output);
process.exit(code);
});
main();
100 changes: 20 additions & 80 deletions lib/cli.js
Expand Up @@ -2,8 +2,7 @@
const Path = require('path');
const Util = require('util');
const Bossy = require('@hapi/bossy');
const Chalk = require('chalk');
const { CLIEngine } = require('eslint');
const { ESLint } = require('eslint');
const Glob = require('glob');
const Insync = require('insync');
const getFilesToLint = Util.promisify(getFiles);
Expand Down Expand Up @@ -65,99 +64,40 @@ const cliArgs = {
};


module.exports.run = async function (argv, callback) {
module.exports.run = async function(argv) {
const args = Bossy.parse(cliArgs, { argv });

if (args instanceof Error) {
return callback(new Error(Bossy.usage(cliArgs, args.message)));
throw new Error(Bossy.usage(cliArgs, args.message));
}

const configFile = args.config;
const globs = args.input;
const ignore = args.ignore;
const fix = args.fix;
const cache = args.cache;
const cwd = args.pwd || process.cwd();

try {
const files = await getFilesToLint({ globs, ignore, cwd });
const result = lintFiles({ configFile, fix, cache, files });
const exitCode = +!!result.errorCount;
const output = formatResults(result);

callback(null, output, exitCode);
} catch (err) {
callback(err);
}
};


function formatResults (result) {
const totalWarnings = result.warningCount;
const totalErrors = result.errorCount;
const totalIssues = totalWarnings + totalErrors;

if (totalIssues < 1) {
return Chalk.green.bold('\nNo issues found!\n');
}

let output = '\n';
const position = Chalk.gray.bold;
const error = Chalk.red;
const warning = Chalk.yellow;
const colorCode = {
2: error,
1: warning
};

result.results.forEach((file) => {
if (file.errorCount < 1 && file.warningCount < 1) {
return;
}

output += 'Problems in: ' + Chalk.dim(file.filePath) + '\n';

file.messages.forEach((msg) => {
const mainStyle = colorCode[msg.severity] || Chalk.gray;

output += mainStyle('\t' + msg.message.slice(0, -1) +
' at line ' + position(Util.format('[%s]', msg.line)) +
', column ' + position(Util.format('[%s]', msg.column)));
output += ' - ' + Chalk.blue(Util.format('(%s)', msg.ruleId));
output += '\n';
});

output += '\n';
});

output += Chalk.bold('Results\n');
output += 'Total ' + error.bold('errors') + ': ' + totalErrors + '\n';
output += 'Total ' + warning.bold('warnings') + ': ' + totalWarnings;
output += '\n';
return output;
}


function lintFiles (options) {
const fix = options.fix;
const linter = new CLIEngine({
configFile: options.configFile,
const files = await getFilesToLint({ globs, ignore, cwd });
const linter = new ESLint({
overrideConfigFile: args.config,
useEslintrc: false,
fix,
cache: options.cache
fix: args.fix,
cache: args.cache
});
const result = await linter.lintFiles(files);
const hasErrors = result.some((current) => {
return current.errorCount > 0;
});

const result = linter.executeOnFiles(options.files);

if (fix) {
CLIEngine.outputFixes(result);
if (args.fix) {
await ESLint.outputFixes(result);
}

return result;
}
const formatter = await linter.loadFormatter('stylish');
const output = formatter.format(result);

return [output, +hasErrors];
};


function getFiles (options, callback) {
function getFiles(options, callback) {
let files = [];
const globOptions = {
realpath: true,
Expand Down
12 changes: 5 additions & 7 deletions package.json
Expand Up @@ -21,21 +21,19 @@
"test": "npm run lint && lab -v -t 100"
},
"engines": {
"node": ">=10.0.0"
"node": ">=12.0.0"
},
"dependencies": {
"@hapi/bossy": "5.x.x",
"chalk": "4.x.x",
"eslint": "7.x.x",
"eslint": "8.0.0-beta.2",
"glob": "7.x.x",
"insync": "2.x.x"
},
"devDependencies": {
"@hapi/lab": "22.x.x",
"@hapi/lab": "24.x.x",
"cb-barrier": "1.x.x",
"fs-extra": "9.x.x",
"stand-in": "4.x.x",
"strip-ansi": "6.x.x"
"fs-extra": "10.x.x",
"stand-in": "4.x.x"
},
"keywords": [
"belly-button",
Expand Down

0 comments on commit beaf30a

Please sign in to comment.