Skip to content

Commit

Permalink
Update own config to new flat ESLint (#11)
Browse files Browse the repository at this point in the history
* Upgrade dependencies

* Upgrade to ESLint v9 (alpha)

* Upgrade own ESLint config to new flat config

Also added package "globals"

* Update folders that ESLint should ignore

* Fix ESLint code violations

* Add global ignore pattern to docs

* Only test with newer versions of node

* Only test on latest node version

Otherwise, v9 of ESLint can't be installed

* Run npm with `--legacy-peer-deps` flag

This is because we are using an alpha version of ESLint.
  • Loading branch information
Splines authored Jan 4, 2024
1 parent 82e8b10 commit d3ae09d
Show file tree
Hide file tree
Showing 10 changed files with 165 additions and 148 deletions.
36 changes: 0 additions & 36 deletions .eslintrc.js

This file was deleted.

4 changes: 2 additions & 2 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ jobs:
strategy:
matrix:
os: [ubuntu-latest]
node: [16, 17, 18, 19, 20, 21]
node: [18, 19, 20, 21]
runs-on: ${{ matrix.os }}
steps:
- name: Checkout
Expand All @@ -22,7 +22,7 @@ jobs:
with:
node-version: ${{ matrix.node }}
- name: Install dependencies
run: npm install
run: npm install --legacy-peer-deps
env:
CI: true
- name: Run Mocha tests
Expand Down
10 changes: 5 additions & 5 deletions .mocharc.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
module.exports = {
"spec": "tests/**/*.js",
"ignore": [
"tests/fixtures/**"
],
}
spec: "tests/**/*.js",
ignore: [
"tests/fixtures/**",
],
};
3 changes: 2 additions & 1 deletion .vscode/settings.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
{
"eslint.format.enable": true,
"eslint.experimental.useFlatConfig": true,
"[javascript]": {
"editor.formatOnSave": false, // to avoid formatting twice (ESLint + VSCode)
"editor.defaultFormatter": "dbaeumer.vscode-eslint"
Expand All @@ -8,5 +9,5 @@
"source.fixAll.eslint": "explicit"
},
// this disables VSCode built-int formatter (instead we want to use ESLint)
"javascript.validate.enable": false
"javascript.validate.enable": false,
}
10 changes: 10 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -62,13 +62,23 @@ const customGlobals = {
MyGlobalVariableOrFunctionOrClassOrWhatever: "readable",
};

// [1] https://eslint.org/docs/latest/use/configure/configuration-files-new#globally-ignoring-files-with-ignores

export default [
js.configs.recommended,
erb.configs.recommended,
// Globally ignoring the following files
// "Note that only global ignores patterns can match directories.
// 'ignores' patterns that are specific to a configuration will
// only match file names." ~ see [1]
{
ignores: [
"node_modules/",
"tests/fixtures/",
"tmp/",
],
},
{
plugins: {
"@stylistic": stylistic,
},
Expand Down
40 changes: 40 additions & 0 deletions eslint.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
const js = require("@eslint/js");
const stylistic = require("@stylistic/eslint-plugin");
const globals = require("globals");

const customizedStylistic = stylistic.configs.customize({
"indent": 2,
"jsx": false,
"quote-props": "always",
"semi": "always",
"brace-style": "1tbs",
});

module.exports = [
js.configs.recommended,
{
ignores: [
"node_modules/",
"tests/fixtures/",
"tmp/",
],
},
{
plugins: {
"@stylistic": stylistic,
},
rules: {
...customizedStylistic.rules,
"no-unused-vars": ["warn", { argsIgnorePattern: "^_" }],
"@stylistic/quotes": ["error", "double", { avoidEscape: true }],
},
languageOptions: {
ecmaVersion: 2024,
sourceType: "module",
globals: {
...globals.node,
...globals.mocha,
},
},
},
];
2 changes: 1 addition & 1 deletion lib/postprocess.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
const cache = require("./cache.js");
const { coordinatesToIndex, indexToColumn } = require("./file_coordinates.js");
const { coordinatesToIndex } = require("./file_coordinates.js");
const { calculateOffset } = require("./offset_calculation.js");
const { transformFix } = require("./autofix.js");

Expand Down
7 changes: 5 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -33,13 +33,16 @@
"devDependencies": {
"@stylistic/eslint-plugin": "^1.3.3",
"chai": "^4.3.10",
"eslint": "^8.54.0",
"eslint": "^9.0.0-alpha.0",
"globals": "^13.24.0",
"mocha": "^10.2.0"
},
"scripts": {
"lint": "eslint .",
"lint-fix": "eslint --fix .",
"test": "mocha",
"whats-included": "npm pack --dry-run",
"bump-version": "npm run test && npm version --no-git-tag-version",
"publish-final": "npm run test && npm publish"
}
}
}
2 changes: 1 addition & 1 deletion tests/postprocess.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ const cache = require("../lib/cache.js");

describe("postprocess", () => {
it("deletes file from cache after postprocessing", () => {
const text = `console.log("Hello world!");`;
const text = 'console.log("Hello world!");';
const name = "testfile.js";

pre(text, name);
Expand Down
Loading

0 comments on commit d3ae09d

Please sign in to comment.