Skip to content

Commit

Permalink
update eslint config
Browse files Browse the repository at this point in the history
  • Loading branch information
jonluca committed Oct 10, 2024
1 parent eeb97de commit 447f9ad
Show file tree
Hide file tree
Showing 11 changed files with 1,443 additions and 646 deletions.
2 changes: 1 addition & 1 deletion .eslintrc.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
# https://jstools.dev/eslint-config/

root: true
extends: "@jsdevtools"
extends: "./eslint-config/lib/index.js"
env:
node: true
browser: true
69 changes: 69 additions & 0 deletions eslint-config/lib/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
"use strict";

const universalRules = require("./universal-rules");
const universalJSDocRules = require("./universal-jsdoc-rules");
const javascriptRules = require("./javascript-rules");
const javascriptJSDocRules = require("./javascript-jsdoc-rules");
const javascriptTestRules = require("./javascript-test-rules");

module.exports = {
plugins: [
"jsdoc",
],
overrides: [
/**
* JavaScript source files
*/
{
files: ["**/*.{js,jsx}"],
excludedFiles: "test/**",
parserOptions: {
sourceType: "script",
ecmaVersion: 2020,
ecmaFeatures: {
jsx: true,
},
},
plugins: [
"jsdoc",
],
env: {
es2020: true,
commonjs: true,
"shared-node-browser": true,
},
rules: {
...universalRules,
...universalJSDocRules,
...javascriptRules,
...javascriptJSDocRules,
}
},

/**
* JavaScript test files
*/
{
files: ["test/**/*.{js,jsx}"],
parserOptions: {
sourceType: "script",
ecmaVersion: 2020,
},
ecmaFeatures: {
jsx: true,
},
env: {
es2020: true,
commonjs: true,
"shared-node-browser": true,
mocha: true,
jasmine: true,
},
rules: {
...universalRules,
...javascriptRules,
...javascriptTestRules,
}
},
],
};
36 changes: 36 additions & 0 deletions eslint-config/lib/javascript-jsdoc-rules.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
"use strict";

/**
* JSDoc rules for JavaScript and TypeScript
*/
module.exports = {
/**
* @see https://github.com/gajus/eslint-plugin-jsdoc#eslint-plugin-jsdoc-rules-check-types
*/
"jsdoc/check-types": "warn",

/**
* @see https://github.com/gajus/eslint-plugin-jsdoc#eslint-plugin-jsdoc-rules-no-undefined-types
*/
"jsdoc/no-undefined-types": "warn",

/**
* @see https://github.com/gajus/eslint-plugin-jsdoc#eslint-plugin-jsdoc-rules-require-param-type
*/
"jsdoc/require-param-type": "warn",

/**
* @see https://github.com/gajus/eslint-plugin-jsdoc#eslint-plugin-jsdoc-rules-require-property-type
*/
"jsdoc/require-property-type": "warn",

/**
* @see https://github.com/gajus/eslint-plugin-jsdoc#eslint-plugin-jsdoc-rules-require-returns-type
*/
"jsdoc/require-returns-type": "warn",

/**
* @see https://github.com/gajus/eslint-plugin-jsdoc#eslint-plugin-jsdoc-rules-valid-types
*/
"jsdoc/valid-types": "warn",
};
190 changes: 190 additions & 0 deletions eslint-config/lib/javascript-rules.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,190 @@
"use strict";

/**
* These rules ONLY apply to JavaScript, not TypeScript.
*/
module.exports = {
/**
* Enforce one true brace style
*
* @see https://eslint.org/docs/rules/brace-style
*/
"brace-style": [
"error",
"stroustrup",
{
// allow opening and closing brace to be on the same line
allowSingleLine: true,
},
],

/**
* Enforce spacing after comma (but not before)
*
* @see https://eslint.org/docs/rules/comma-spacing
*/
"comma-spacing": [
"warn",
{
before: false,
after: true,
},
],

/**
* Require default parameters to be the last parameters in the function
*
* @see https://eslint.org/docs/rules/default-param-last
*/
"default-param-last": "error",

/**
* Encourages use of dot notation whenever possible
*
* @see https://eslint.org/docs/rules/dot-notation
*/
"dot-notation": "error",

/**
* Disallow spaces after the function name in function calls
*
* @see https://eslint.org/docs/rules/func-call-spacing
*/
"func-call-spacing": "error",

/**
* Require a space before and after keywords
*
* @see https://eslint.org/docs/rules/keyword-spacing
*/
"keyword-spacing": "error",

/**
* Require a blank line between class members
*
* @see https://eslint.org/docs/rules/lines-between-class-members
*/
"lines-between-class-members": [
"error",
"always",
{
exceptAfterSingleLine: true,
}
],

/**
* Disallow use of the Array constructor
*
* @see https://eslint.org/docs/rules/no-array-constructor
*/
"no-array-constructor": "error",

/**
* Disallow duplicate name in class members
*
* @see https://eslint.org/docs/rules/no-dupe-class-members
*/
"no-dupe-class-members": "error",

/**
* Warn about empty functions
*
* @see https://eslint.org/docs/rules/no-empty-function
*/
"no-empty-function": "warn",

/**
* Disallow unnecessary semicolons
*
* @see https://eslint.org/docs/rules/no-extra-semi
*/
"no-extra-semi": "error",

/**
* Disallow unnecessary `return await` statements
*
* @see https://eslint.org/docs/rules/no-return-await
*/
"no-return-await": "error",

/**
* Disallow usage of expressions in statement position
*
* @see https://eslint.org/docs/rules/no-unused-expressions
*/
"no-unused-expressions": [
"error",
{
allowShortCircuit: true, // allow short-circuited expressions (e.g. foo && bar())
allowTernary: true, // allow ternary expressions (e.g. foo ? bar() : baz())
},
],

/**
* Disallow declaration of variables that are not used in the code
*
* @see https://eslint.org/docs/rules/no-unused-vars
*/
"no-unused-vars": [
"error",
{
vars: "all", // check "all" variables (as opposed to just "local" variables)
args: "after-used", // check any arguments that come "after-used" arguments
ignoreRestSiblings: true, // ignore siblings of ...rest params
argsIgnorePattern: "^_", // Ignore params that begin with an underscore
varsIgnorePattern: "^_", // Ignore variables that begin with an underscore
},
],

/**
* Don't allow constructors that are empty or only call super()
*
* @see https://eslint.org/docs/rules/no-useless-constructor
*/
"no-useless-constructor": "error",

/**
* Require double quotes for all strings
*
* @see https://eslint.org/docs/rules/quotes
*/
quotes: [
"error",
"double",
"avoid-escape",
],

/**
* Require async functions to contain an `await` keyword
*
* @see https://eslint.org/docs/rules/require-await
*/
"require-await": "error",

/**
* Require use of semicolons instead of ASI
*
* @see https://eslint.org/docs/rules/semi
*/
semi: "error",

/**
* Require a space between the function name and left paren in function definitions.
* This makes it easier to search for function calls versus declarations.
*
* @see https://eslint.org/docs/rules/
*/
// This makes it easier to search for function definitions versus function calls.
"space-before-function-paren": "error",

/**
* Require the "use strict" pragma, either at the global level or function level,
* depending on whether CommonJS is being used or not
*
* @see https://eslint.org/docs/rules/strict
*/
strict: [
"error",
"safe",
],
};
47 changes: 47 additions & 0 deletions eslint-config/lib/javascript-test-rules.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
"use strict";

/**
* Relax some JavaScript rules for testing purposes
*/
module.exports = {
/**
* Allow empty functions
*
* @see https://eslint.org/docs/rules/no-empty-function
*/
"no-empty-function": "off",

/**
* Allow the new operator to be used for side-effects
*
* @see https://eslint.org/docs/rules/no-new
*/
"no-new": "off",

/**
* Ignore unnecessary `return await` statements
*
* @see https://eslint.org/docs/rules/no-return-await
*/
"no-return-await": "off",

/**
* Warn about usage of expressions in statement position
*
* @see https://eslint.org/docs/rules/no-unused-expressions
*/
"no-unused-expressions": [
"warn",
{
allowShortCircuit: true, // allow short-circuited expressions (e.g. foo && bar())
allowTernary: true, // allow ternary expressions (e.g. foo ? bar() : baz())
},
],

/**
* allow async functions without an `await` keyword
*
* @see https://eslint.org/docs/rules/require-await
*/
"require-await": "off",
};
Loading

0 comments on commit 447f9ad

Please sign in to comment.