Skip to content

Commit

Permalink
V3 - ESLint 9 + Stylistic
Browse files Browse the repository at this point in the history
  • Loading branch information
TheJaredWilcurt committed Sep 7, 2024
1 parent 38c4f02 commit 579d105
Show file tree
Hide file tree
Showing 7 changed files with 828 additions and 436 deletions.
12 changes: 7 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,12 +1,14 @@
# eslint-config-tjw-base

The Jared Wilcurt's base ESLint rules
The Jared Wilcurt's base ESLint 9+ rules for ESM projects.

For CJS and ESLint < v9, use v2.x releases.


## Using this

1. `npm install --save-dev eslint eslint-config-tjw-base`
1. In your `.eslintrc.js` add `tjw-base` to your `extends` like so:
1. `npm install --save-dev eslint eslint-config-tjw-base @stylistic/eslint-plugin-js`
1. In your `eslint.config.js` add `tjw-base` to your `extends` like so:
```js
module.exports = {
extends: [
Expand All @@ -18,8 +20,8 @@ The Jared Wilcurt's base ESLint rules
If you already have a `no-restricted-syntax` rule, you can merge the ones that come with this config with your own, like so:

```js
// .eslintrc.js
const baseRestrictedSyntax = require('eslint-config-tjw-base/no-restricted-syntax.json');
// eslint.config.js
import baseRestrictedSyntax from 'eslint-config-tjw-base/no-restricted-syntax.js';
module.exports = {
extends: [
Expand Down
122 changes: 65 additions & 57 deletions index.js
Original file line number Diff line number Diff line change
@@ -1,167 +1,175 @@
module.exports = {
parserOptions: {
ecmaVersion: 2022,
sourceType: 'module'
import globals from 'globals';
import stylisticJs from '@stylistic/eslint-plugin-js';

export default {
languageOptions: {
globals: {
...globals.browser,
...globals.nodeBuiltin
},
parserOptions: {
ecmaVersion: 2025,
sourceType: 'module'
}
},
env: {
browser: true,
node: true
plugins: {
'@stylistic/js': stylisticJs
},
rules: {
// (a) => a not a => a
'arrow-parens': [
'@stylistic/js/arrow-parens': [
'error',
'always'
],
// } else { not }\n else {
'brace-style': [
'@stylistic/js/brace-style': [
'error',
'1tbs',
{
allowSingleLine: true
}
],
// last item in a list should not have a comma at the end
'comma-dangle': [
'@stylistic/js/comma-dangle': [
'error',
'never'
],
// [a, b] not [a,b] or [a ,b]
'comma-spacing': [
'@stylistic/js/comma-spacing': [
'error',
{
before: false,
after: true
}
],
// commas go at the end of a line, not the start
'comma-style': [
'@stylistic/js/comma-style': [
'error',
'last'
],
// if (a) { a++ } not if (a) a++
curly: [
'error'
],
// allow async-await
'generator-star-spacing': [
'@stylistic/js/generator-star-spacing': [
'off'
],
// 2 space indentation (should match .editorconfig)
indent: [
'@stylistic/js/indent': [
'error',
2,
{
SwitchCase: 1
}
],
// { key: value } not { key:value }
'key-spacing': [
'@stylistic/js/key-spacing': [
'error',
{
afterColon: true,
beforeColon: false
}
],
// { key: value } not {key: value}
'keyword-spacing': [
'@stylistic/js/keyword-spacing': [
'error',
{
before: true,
after: true
}
],
// let a = 1; not let a = 1;
'no-multi-spaces': [
'@stylistic/js/no-multi-spaces': [
'error'
],
// No empty lines at top or bottom or file (except 1 EOF for git)
// and no more than 2 empty returns in a file
'no-multiple-empty-lines': [
'@stylistic/js/no-multiple-empty-lines': [
'error',
{
max: 2,
maxBOF: 0,
maxEOF: 0
}
],
'no-restricted-syntax': [
'error',
{
selector: 'Property[method="true"]',
message: 'No shortform methods. x: function (). not x()'
}
],
// Remove unused defined variables
'no-unused-vars': [
'error'
],
// Don't reference a variable that is not defined
'no-undef': [
'error'
],
// Only allow let and const, no var
'no-var': [
'error'
],
// Curly braces start and end should match in a sane way
'object-curly-spacing': [
'@stylistic/js/object-curly-spacing': [
'error',
'always'
],
// Consistent operator placement on multiple lines
'operator-linebreak': [
'@stylistic/js/operator-linebreak': [
'error',
'after'
],
// Define each variable on it's own line
'one-var': [
'error',
'never'
],
// Don't have returns as the first or last character in a function or if statement
'padded-blocks': [
'@stylistic/js/padded-blocks': [
'error',
'never'
],
// Single quotes are used by ~80% of the JS community
quotes: [
'@stylistic/js/quotes': [
'error',
'single'
],
// Only require quotes around object keys that need them
'quote-props': [
'@stylistic/js/quote-props': [
'error',
'as-needed'
],
// TC39 strongly reccommends not relying on ASI
semi: [
'@stylistic/js/semi': [
'error',
'always'
],
// if (a) {} not if (a){}
'space-before-blocks': [
'@stylistic/js/space-before-blocks': [
'error',
'always'
],
// function name () {} not function name() {}
'space-before-function-paren': [
'@stylistic/js/space-before-function-paren': [
'error',
'always'
],
// a(b) not a( b )
'space-in-parens': [
'@stylistic/js/space-in-parens': [
'error',
'never'
],
// 1 + 2 not 1+2
'space-infix-ops': [
'@stylistic/js/space-infix-ops': [
'error'
],
// Comments begin with a space
'spaced-comment': [
'@stylistic/js/spaced-comment': [
'error',
'always'
],
// if (a) { a++ } not if (a) a++
curly: [
'error'
],
'no-restricted-syntax': [
'error',
{
selector: 'Property[method="true"]',
message: 'No shortform methods. x: function (). not x()'
}
],
// Remove unused defined variables
'no-unused-vars': [
'error'
],
// Don't reference a variable that is not defined
'no-undef': [
'error'
],
// Only allow let and const, no var
'no-var': [
'error'
],
// Define each variable on it's own line
'one-var': [
'error',
'never'
]
}
};
6 changes: 6 additions & 0 deletions no-restricted-syntax.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
export default const baseRestrictedSyntax = [
{
selector: 'Property[method="true"]',
message: 'No shortform methods. x: function (). not x()'
}
];
6 changes: 0 additions & 6 deletions no-restricted-syntax.json

This file was deleted.

Loading

0 comments on commit 579d105

Please sign in to comment.