Skip to content

Commit

Permalink
Upgrade eslint and extract config (#645)
Browse files Browse the repository at this point in the history
* Upgrade eslint and extract config

- upgrade eslint to 5.15.3
- upgrade eslint-plugin-import to 2.16.0
- correctly use the import plugin
- remove linebreak-style (fixes #502)
- use eslint:recommended (fixes #589, fixes #480)

In a later change we should turn on airbnb-base for maintaining via a script that switches this.

In a later change, we should turn on several rules that guard against potential bugs, such as `no-shadow` `no-undefined` `no-var`; additionally we can add stylistic consistency without forcing style choises such as consistent spacing (but not required).

* Saving files before refreshing line endings

* Normalize all the line endings
  • Loading branch information
SleeplessByte authored and tejasbubane committed Mar 25, 2019
1 parent d209ecf commit b91ba55
Show file tree
Hide file tree
Showing 207 changed files with 3,131 additions and 2,549 deletions.
26 changes: 26 additions & 0 deletions .eslintrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
{
"root": true,
"parser": "babel-eslint",
"parserOptions": {
"ecmaVersion": 7,
"sourceType": "module"
},
"env": {
"es6": true,
"node": true,
"jest": true
},
"extends": [
"eslint:recommended",
"plugin:import/errors",
"plugin:import/warnings"
],
"rules": {
"linebreak-style": "off",

"import/extensions": "off",
"import/no-default-export": "off",
"import/no-unresolved": "off",
"import/prefer-default-export": "off"
}
}
1 change: 1 addition & 0 deletions .gitattributes
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
* text=auto
64 changes: 64 additions & 0 deletions bin/tools/copy-eslint-config
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
#!/usr/bin/env node

/**
* This copies the current .eslintrc to a specific exercise folder or to all
* of them if an exercise folder is not given. Merges the version field in case
* it's set.
*
* Usage:
*
* ./bin/tools/copy-eslint-config <exercise>
*/

// @ts-check

const fs = require('fs');
const path = require('path');

const ROOT_PATH = path.join(__dirname, '..', '..');
const BABEL_CONFIG_PATH = path.join(ROOT_PATH, '.eslintrc');
const EXERCISE = process.argv.slice(2).find(arg => !arg.startsWith('-'));

process.stdout.write(`=> copy eslint config for ${EXERCISE || 'all exercises'}\n`);


function execute(exercise) {
const EXERCISE_DIR = path.join(ROOT_PATH, 'exercises', exercise);
const destination = path.join(EXERCISE_DIR, path.basename(BABEL_CONFIG_PATH));

fs.copyFile(BABEL_CONFIG_PATH, destination, (err) => {
if (err) {
process.stderr.write(`=> error for ${exercise}: ${err.message}\n`);
} else {
process.stdout.write(`=> copied eslint config to ${exercise}\n`);
}
});

}

if (!EXERCISE) {
process.stdin.resume();
process.stdout.write('?> are you sure? [Y/n]\n');
process.stdin.once('data', (data) => {
process.stdin.pause();

const input = data.toString().trim();

if (!/^(?:\s?|y|yes)$/i.test(input)) {
process.stdout.write('=> ok bye\n');
process.exit(0);
return;
}

fs.readdir(path.join(ROOT_PATH, 'exercises'), (err, exercises) => {
if (err) {
process.stderr.write(err.message);
process.exit(-1);
}

exercises.forEach(execute);
});
});
} else {
execute(EXERCISE);
}
26 changes: 26 additions & 0 deletions exercises/accumulate/.eslintrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
{
"root": true,
"parser": "babel-eslint",
"parserOptions": {
"ecmaVersion": 7,
"sourceType": "module"
},
"env": {
"es6": true,
"node": true,
"jest": true
},
"extends": [
"eslint:recommended",
"plugin:import/errors",
"plugin:import/warnings"
],
"rules": {
"linebreak-style": "off",

"import/extensions": "off",
"import/no-default-export": "off",
"import/no-unresolved": "off",
"import/prefer-default-export": "off"
}
}
24 changes: 2 additions & 22 deletions exercises/accumulate/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,8 @@
"@babel/preset-env": "^7.4.2",
"babel-eslint": "^10.0.1",
"babel-jest": "^24.5.0",
"eslint": "^5.12.1",
"eslint-config-airbnb-base": "^13.1.0",
"eslint-plugin-import": "^2.15.0",
"eslint": "^5.15.3",
"eslint-plugin-import": "^2.16.0",
"jest": "^24.5.0"
},
"jest": {
Expand All @@ -30,25 +29,6 @@
"lint": "eslint .",
"lint-test": "eslint . && jest --no-cache ./* "
},
"eslintConfig": {
"parser": "babel-eslint",
"parserOptions": {
"ecmaVersion": 7,
"sourceType": "module"
},
"env": {
"es6": true,
"node": true,
"jest": true
},
"extends": "airbnb-base",
"rules": {
"import/no-unresolved": "off",
"import/extensions": "off",
"import/prefer-default-export": "off",
"import/no-default-export": "off"
}
},
"license": "MIT",
"dependencies": {}
}
26 changes: 26 additions & 0 deletions exercises/acronym/.eslintrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
{
"root": true,
"parser": "babel-eslint",
"parserOptions": {
"ecmaVersion": 7,
"sourceType": "module"
},
"env": {
"es6": true,
"node": true,
"jest": true
},
"extends": [
"eslint:recommended",
"plugin:import/errors",
"plugin:import/warnings"
],
"rules": {
"linebreak-style": "off",

"import/extensions": "off",
"import/no-default-export": "off",
"import/no-unresolved": "off",
"import/prefer-default-export": "off"
}
}
24 changes: 2 additions & 22 deletions exercises/acronym/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,8 @@
"@babel/preset-env": "^7.4.2",
"babel-eslint": "^10.0.1",
"babel-jest": "^24.5.0",
"eslint": "^5.12.1",
"eslint-config-airbnb-base": "^13.1.0",
"eslint-plugin-import": "^2.15.0",
"eslint": "^5.15.3",
"eslint-plugin-import": "^2.16.0",
"jest": "^24.5.0"
},
"jest": {
Expand All @@ -30,25 +29,6 @@
"lint": "eslint .",
"lint-test": "eslint . && jest --no-cache ./* "
},
"eslintConfig": {
"parser": "babel-eslint",
"parserOptions": {
"ecmaVersion": 7,
"sourceType": "module"
},
"env": {
"es6": true,
"node": true,
"jest": true
},
"extends": "airbnb-base",
"rules": {
"import/no-unresolved": "off",
"import/extensions": "off",
"import/prefer-default-export": "off",
"import/no-default-export": "off"
}
},
"license": "MIT",
"dependencies": {}
}
26 changes: 26 additions & 0 deletions exercises/all-your-base/.eslintrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
{
"root": true,
"parser": "babel-eslint",
"parserOptions": {
"ecmaVersion": 7,
"sourceType": "module"
},
"env": {
"es6": true,
"node": true,
"jest": true
},
"extends": [
"eslint:recommended",
"plugin:import/errors",
"plugin:import/warnings"
],
"rules": {
"linebreak-style": "off",

"import/extensions": "off",
"import/no-default-export": "off",
"import/no-unresolved": "off",
"import/prefer-default-export": "off"
}
}
24 changes: 2 additions & 22 deletions exercises/all-your-base/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,8 @@
"@babel/preset-env": "^7.4.2",
"babel-eslint": "^10.0.1",
"babel-jest": "^24.5.0",
"eslint": "^5.12.1",
"eslint-config-airbnb-base": "^13.1.0",
"eslint-plugin-import": "^2.15.0",
"eslint": "^5.15.3",
"eslint-plugin-import": "^2.16.0",
"jest": "^24.5.0"
},
"jest": {
Expand All @@ -30,25 +29,6 @@
"lint": "eslint .",
"lint-test": "eslint . && jest --no-cache ./* "
},
"eslintConfig": {
"parser": "babel-eslint",
"parserOptions": {
"ecmaVersion": 7,
"sourceType": "module"
},
"env": {
"es6": true,
"node": true,
"jest": true
},
"extends": "airbnb-base",
"rules": {
"import/no-unresolved": "off",
"import/extensions": "off",
"import/prefer-default-export": "off",
"import/no-default-export": "off"
}
},
"license": "MIT",
"dependencies": {}
}
26 changes: 26 additions & 0 deletions exercises/allergies/.eslintrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
{
"root": true,
"parser": "babel-eslint",
"parserOptions": {
"ecmaVersion": 7,
"sourceType": "module"
},
"env": {
"es6": true,
"node": true,
"jest": true
},
"extends": [
"eslint:recommended",
"plugin:import/errors",
"plugin:import/warnings"
],
"rules": {
"linebreak-style": "off",

"import/extensions": "off",
"import/no-default-export": "off",
"import/no-unresolved": "off",
"import/prefer-default-export": "off"
}
}
24 changes: 2 additions & 22 deletions exercises/allergies/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,8 @@
"@babel/preset-env": "^7.4.2",
"babel-eslint": "^10.0.1",
"babel-jest": "^24.5.0",
"eslint": "^5.12.1",
"eslint-config-airbnb-base": "^13.1.0",
"eslint-plugin-import": "^2.15.0",
"eslint": "^5.15.3",
"eslint-plugin-import": "^2.16.0",
"jest": "^24.5.0"
},
"jest": {
Expand All @@ -30,25 +29,6 @@
"lint": "eslint .",
"lint-test": "eslint . && jest --no-cache ./* "
},
"eslintConfig": {
"parser": "babel-eslint",
"parserOptions": {
"ecmaVersion": 7,
"sourceType": "module"
},
"env": {
"es6": true,
"node": true,
"jest": true
},
"extends": "airbnb-base",
"rules": {
"import/no-unresolved": "off",
"import/extensions": "off",
"import/prefer-default-export": "off",
"import/no-default-export": "off"
}
},
"license": "MIT",
"dependencies": {}
}
26 changes: 26 additions & 0 deletions exercises/alphametics/.eslintrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
{
"root": true,
"parser": "babel-eslint",
"parserOptions": {
"ecmaVersion": 7,
"sourceType": "module"
},
"env": {
"es6": true,
"node": true,
"jest": true
},
"extends": [
"eslint:recommended",
"plugin:import/errors",
"plugin:import/warnings"
],
"rules": {
"linebreak-style": "off",

"import/extensions": "off",
"import/no-default-export": "off",
"import/no-unresolved": "off",
"import/prefer-default-export": "off"
}
}
Loading

0 comments on commit b91ba55

Please sign in to comment.