Skip to content

Commit

Permalink
Merge pull request #13913 from Swiftb0y/chore/cleanup-eslint-config
Browse files Browse the repository at this point in the history
Cleanup ESLint config
  • Loading branch information
acolombier authored Nov 22, 2024
2 parents d07387b + 53b37de commit 9022fb6
Show file tree
Hide file tree
Showing 8 changed files with 165 additions and 175 deletions.
2 changes: 2 additions & 0 deletions .github/workflows/pre-commit.yml
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,8 @@ jobs:
if: github.event_name == 'pull_request'
env:
SKIP: no-commit-to-branch
# https://github.com/paleite/eslint-plugin-diff?tab=readme-ov-file#ci-setup
ESLINT_PLUGIN_DIFF_COMMIT: ${{ github.event.pull_request.base.ref }}
with:
# HEAD is the not yet integrated PR merge commit +refs/pull/xxxx/merge
# HEAD^1 is the PR target branch and HEAD^2 is the HEAD of the source branch
Expand Down
5 changes: 2 additions & 3 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -72,16 +72,15 @@ repos:
args: [--fix, --report-unused-disable-directives]
files: \.m?[jt]s$
types: [file]
verbose: true # always show output so we don't swallow warnings
stages:
- pre-commit
- manual
additional_dependencies:
- eslint@^9.14.0
- "@eslint/js"
- "@eslint/eslintrc"
- typescript-eslint
- eslint-plugin-jsdoc@^v50.4.3
- "@typescript-eslint/eslint-plugin"
- "@typescript-eslint/parser"
- eslint-plugin-diff@^2.0.3
- repo: local
hooks:
Expand Down
288 changes: 147 additions & 141 deletions eslint.config.cjs
Original file line number Diff line number Diff line change
@@ -1,154 +1,160 @@
const jsdoc = require("eslint-plugin-jsdoc");
const typescriptEslint = require("@typescript-eslint/eslint-plugin");
const tsParser = require("@typescript-eslint/parser");
const js = require("@eslint/js");

const {
FlatCompat,
} = require("@eslint/eslintrc");

const compat = new FlatCompat({
baseDirectory: __dirname,
recommendedConfig: js.configs.recommended,
allConfig: js.configs.all
});
const eslint = require("@eslint/js");
const tseslint = require("typescript-eslint");
const jsdoc = require("eslint-plugin-jsdoc");
const diff = require("eslint-plugin-diff");

module.exports = [{
ignores: [
"res/controllers/lodash.mixxx.js",
"res/controllers/Novation-Launchpad MK2-scripts.js",
"res/controllers/Novation-Launchpad Mini MK3-scripts.js",
"res/controllers/Novation-Launchpad-scripts.js",
],
}, ...compat.extends("eslint:recommended", "plugin:jsdoc/recommended", "plugin:diff/diff"), {
// https://github.com/paleite/eslint-plugin-diff/issues/47#issuecomment-2480733106
const diffConfig = {
plugins: {
jsdoc,
"@typescript-eslint": typescriptEslint,
diff,
},

languageOptions: {
globals: {
console: "readonly",
},

parser: tsParser,
ecmaVersion: 7,
sourceType: "script",
processor: diff.processors.diff,
}

module.exports = tseslint.config(
{
// these are autogenerated and thus should not be linted at all.
ignores: [
"res/controllers/lodash.mixxx.js",
"res/controllers/Novation-Launchpad MK2-scripts.js",
"res/controllers/Novation-Launchpad Mini MK3-scripts.js",
"res/controllers/Novation-Launchpad-scripts.js",
],
},

settings: {
jsdoc: {
preferredTypes: {
object: "Object",
},
{
languageOptions: {
ecmaVersion: 7,
sourceType: "script",
},
},

rules: {
"array-bracket-spacing": "warn",
"block-spacing": "warn",

"brace-style": ["warn", "1tbs", {
allowSingleLine: true,
}],

curly: "warn",
camelcase: "warn",
"comma-spacing": "warn",

"computed-property-spacing": ["warn", "never", {
enforceForClassMembers: true,
}],

"dot-location": ["warn", "property"],
"dot-notation": "warn",
eqeqeq: ["error", "always"],
"func-call-spacing": "warn",

"func-style": ["error", "expression", {
allowArrowFunctions: true,
}],

indent: ["warn", 4],
"key-spacing": "warn",
"keyword-spacing": "warn",
"linebreak-style": ["warn", "unix"],
"newline-per-chained-call": "warn",
"no-constructor-return": "warn",
"no-extra-bind": "warn",
"no-sequences": "warn",
"no-useless-call": "warn",
"no-useless-return": "warn",
"no-trailing-spaces": "warn",

"no-unneeded-ternary": ["warn", {
defaultAssignment: false,
}],

"no-unused-vars": ["error", {
argsIgnorePattern: "^_",
}],

"no-var": "warn",

"object-curly-newline": ["warn", {
consistent: true,
multiline: true,
}],

"object-curly-spacing": "warn",
"prefer-const": "warn",
"prefer-regex-literals": "warn",
"prefer-template": "warn",
quotes: ["warn", "double"],
"require-atomic-updates": "error",
semi: "warn",
"semi-spacing": "warn",
"space-before-blocks": ["warn", "always"],
"space-before-function-paren": ["warn", "never"],
"space-in-parens": "warn",
yoda: "warn",
},
}, ...compat.extends("plugin:@typescript-eslint/recommended").map(config => ({
...config,
files: ["res/controllers/*.d.ts"],
})), {
files: ["res/controllers/*.d.ts"],

rules: {
"no-unused-vars": "off",
{
plugins: {
jsdoc,
}
},
}, {
files: ["**/*.mjs"],

languageOptions: {
ecmaVersion: 5,
sourceType: "module",
eslint.configs.recommended,
tseslint.configs.recommended,
jsdoc.configs['flat/recommended'],
diffConfig,
{
files: ["res/controllers/**/*"],
languageOptions: {
globals: {
// QJSEngine::ConsoleExtension, https://doc.qt.io/qt-6/qtquick-debugging.html#console-api
"console": "readonly",
// lodash, deprecated
"_": "readonly",
// Mixxx custom
"ColorMapper": "readonly",
"components": "readonly",
"engine": "readonly",
"midi": "readonly",
// common-controller-scripts globals
"print": "readonly",
"printObject": "readonly",
"stringifyObject": "readonly",
"arrayContains": "readonly",
"secondstominutes": "readonly",
"msecondstominutes": "readonly",
"colorCodeToObject": "readonly",
"colorCodeFromObject": "readonly",
"script": "readonly",
"bpm": "readonly",
"ButtonState": "readonly",
"LedState": "readonly",
"Controller": "readonly",
"Button": "readonly",
"Control": "readonly",
"Deck": "readonly"
}
}
},
}, {
files: ["res/controllers/common-hid-packet-parser.js"],

languageOptions: {
globals: {
console: "readonly",
{
// vanilla rule config from previous `.eslintrc`
rules: {
"array-bracket-spacing": "warn",
"block-spacing": "warn",

"brace-style": ["warn", "1tbs", {
allowSingleLine: true,
}],

curly: "warn",
camelcase: "warn",
"comma-spacing": "warn",

"computed-property-spacing": ["warn", "never", {
enforceForClassMembers: true,
}],

"dot-location": ["warn", "property"],
"dot-notation": "warn",
eqeqeq: ["error", "always"],
"func-call-spacing": "warn",

"func-style": ["error", "expression", {
allowArrowFunctions: true,
}],

indent: ["warn", 4],
"key-spacing": "warn",
"keyword-spacing": "warn",
"linebreak-style": ["warn", "unix"],
"newline-per-chained-call": "warn",
"no-constructor-return": "warn",
"no-extra-bind": "warn",
"no-sequences": "warn",
"no-useless-call": "warn",
"no-useless-return": "warn",
"no-trailing-spaces": "warn",

"no-unneeded-ternary": ["warn", {
defaultAssignment: false,
}],

"no-var": "warn",

"object-curly-newline": ["warn", {
consistent: true,
multiline: true,
}],

"object-curly-spacing": "warn",
"prefer-const": "warn",
"prefer-regex-literals": "warn",
"prefer-template": "warn",
quotes: ["warn", "double"],
"require-atomic-updates": "error",
semi: "warn",
"semi-spacing": "warn",
"space-before-blocks": ["warn", "always"],
"space-before-function-paren": ["warn", "never"],
"space-in-parens": "warn",
yoda: "warn",
},
},

rules: {
camelcase: "off",
{
// special rules required for the typescript plugin
rules: {
// Note: you must disable the base rule as it can report incorrect errors
"no-unused-vars": "off",
"@typescript-eslint/no-unused-vars": ["error", {
argsIgnorePattern: "^_",
}],
// no need for jsdoc type annotation, the typescript syntax already requires it.
"jsdoc/require-param-type": "off",
"jsdoc/require-returns-type": "off",
// this is commonly needed in ComponentsJS
"@typescript-eslint/no-this-alias": "off",
"@typescript-eslint/no-explicit-any": "off",
}
},
}, {
files: ["res/controllers/*.js"],
ignores: ["res/controllers/common-hid-packet-parser.js"],

languageOptions: {
globals: {
console: "readonly",
svg: "writable",
HIDController: "writable",
HIDDebug: "writable",
HIDPacket: "writable",
controller: "writable",
},
{
// JSDoc specific stuff
rules: {
// the style here is too mixed currently, disable for now
"jsdoc/tag-lines": "off"
}
},
}];
);
24 changes: 0 additions & 24 deletions res/controllers/.eslintrc.json

This file was deleted.

4 changes: 3 additions & 1 deletion res/controllers/common-hid-packet-parser.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
/* global controller */
// fixing names to to be camelcase would break the API
// so disable it for the entire file for now.
/* eslint-disable camelcase */

/**
* Common HID script debugging function. Just to get logging with 'HID' prefix.
Expand Down
8 changes: 5 additions & 3 deletions res/controllers/console-api.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -108,21 +108,23 @@ declare namespace console {
/**
* Prints the current number of times a particular piece of code has run, along with a message.
*
* @param label
* @param label message to be prepended before the count
*/
function count(label?: string): void;

/**
* Turns on the JavaScript profiler.
*
* @deprecated Not usable for controller mappings for now [see QTBUG-65419]{@link https://bugreports.qt.io/browse/QTBUG-65419}
* @param label measurement label
* @deprecated Not usable for controller mappings for now [see QTBUG-65419]{@link https://bugreports.qt.io/browse/QTBUG-65419}
*/
function profile(label?: string): void;

/**
* Turns off the JavaScript profiler.
*
* @deprecated Not usable for controller mappings for now [see QTBUG-65419]{@link https://bugreports.qt.io/browse/QTBUG-65419}
* @param label measurement label
* @deprecated Not usable for controller mappings for now [see QTBUG-65419]{@link https://bugreports.qt.io/browse/QTBUG-65419}
*/
function profileEnd(label?: string): void;

Expand Down
Loading

0 comments on commit 9022fb6

Please sign in to comment.