Skip to content

Commit

Permalink
feat: update to flat configs (#11)
Browse files Browse the repository at this point in the history
  • Loading branch information
HW13 authored Mar 15, 2024
1 parent c2c17b4 commit 15abd48
Show file tree
Hide file tree
Showing 14 changed files with 326 additions and 228 deletions.
6 changes: 3 additions & 3 deletions .github/workflows/release.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -11,16 +11,16 @@ jobs:
runs-on: ubuntu-latest
needs: validate
steps:
- uses: actions/checkout@v3
- uses: actions/checkout@v4
with:
token: ${{ secrets.GH_PAT }}
fetch-depth: 0
- run: |
git config --global user.name 'github-actions[bot]'
git config --global user.email 'github-actions[bot]@users.noreply.github.com'
- uses: actions/setup-node@v3
- uses: actions/setup-node@v4
with:
node-version: '18.x'
node-version: '20.x'
registry-url: 'https://registry.npmjs.org'
- run: npm install --package-lock=false
- run: npm run version:bump -- --yes
Expand Down
9 changes: 3 additions & 6 deletions .github/workflows/validate.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,12 @@ on: [pull_request, workflow_call]
jobs:
validate:
runs-on: ubuntu-latest
strategy:
matrix:
node: ['16', '18']
steps:
- uses: actions/checkout@v3
- uses: actions/setup-node@v3
- uses: actions/checkout@v4
- uses: actions/setup-node@v4
with:
node-version: '20.x'
registry-url: 'https://registry.npmjs.org/'
node-version: ${{ matrix.node }}
- run: npm install
- run: npm run bootstrap
- run: npm run validate
1 change: 1 addition & 0 deletions .node-version
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
20.11.1
5 changes: 5 additions & 0 deletions eslint.config.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
import configJs from '@autotelic/eslint-config-js'

export default [
configJs
]
3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,15 @@
"scripts": {
"bootstrap": "lerna bootstrap --strict",
"clean": "lerna clean -y && lerna exec -- rm -f package-lock.json && rm -rf package-lock.json node_modules",
"validate": "lerna run lint",
"validate": "eslint .",
"version:bump": "lerna version --conventional-commits --create-release github",
"version:release": "lerna publish from-package"
},
"workspaces": [
"packages/*"
],
"devDependencies": {
"eslint": "^8.57.0",
"lerna": "^6.5.1"
}
}
67 changes: 0 additions & 67 deletions packages/eslint-config-js/.eslintrc.json

This file was deleted.

52 changes: 42 additions & 10 deletions packages/eslint-config-js/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,6 @@

### Usage

Thanks to [`@rushstack/eslint-patch`](https://github.com/microsoft/rushstack/tree/main/eslint/eslint-patch#readme), this package has no peer dependencies other than `eslint`. To use `@autotelic/eslint-config-js` in your project, just run one of the following install commands and add the `.eslintrc.json` suggested below.

#### NPM

```sh
Expand All @@ -18,17 +16,51 @@ npm i --save-dev eslint @autotelic/eslint-config-js
yarn add --dev eslint @autotelic/eslint-config-js
```

#### `.eslintrc.json`
#### `eslint.config.js`

```js
const configJs = require('@autotelic/eslint-config-js')

module.exports = [
configJs,
{
// ...Additional config
}
]

```

#### `eslint.config.mjs`

```js
import configJs from '@autotelic/eslint-config-js'

export default [
configJs,
{
// ...Additional config
}
]

```

#### Configuring Node Version

By default the Node version is set to `^20.x`, if a different or a more specific version is preferred it can be configured as follows:

```js
// eslint.config.js
const configJs = require('@autotelic/eslint-config-js')

```json
{
"extends": ["@autotelic/eslint-config-js"],
"settings": {
"node": {
"version": "^18.x", // Any Node version >= 16
module.exports = [
configJs,
{
settings: {
node: {
version: '20.11.1'
}
}
}
}]
```

### About
Expand Down
75 changes: 73 additions & 2 deletions packages/eslint-config-js/index.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,74 @@
require('@rushstack/eslint-patch/modern-module-resolution')
const standard = require('./standard')

module.exports = require('./.eslintrc.json')
module.exports = {
...standard,
settings: {
node: {
version: '^20.x'
}
},
rules: {
...standard.rules,
'array-bracket-newline': ['error', 'consistent'],
'arrow-body-style': ['error', 'as-needed'],
complexity: ['error', {
max: 15
}],
'default-param-last': ['error'],
'func-names': ['error', 'as-needed'],
'func-style': ['error', 'declaration', {
allowArrowFunctions: true
}],
'function-call-argument-newline': ['error', 'consistent'],
'implicit-arrow-linebreak': ['error', 'beside'],
'max-len': ['error', {
code: 110,
tabWidth: 2,
ignoreComments: true,
ignoreTrailingComments: false,
ignoreStrings: true,
ignoreTemplateLiterals: true,
ignoreUrls: true,
ignoreRegExpLiterals: true
}],
'newline-per-chained-call': ['error', { ignoreChainWithDepth: 3 }],
'no-bitwise': 'error',
'no-confusing-arrow': 'error',
'no-else-return': 'error',
'no-multi-assign': 'error',
'no-nested-ternary': 'error',
'no-return-await': 'error',
'object-shorthand': ['error', 'always'],
'require-atomic-updates': ['error', {
allowProperties: true
}],
'import/default': 'error',
'import/named': 'error',
'import/no-cycle': ['error', {
ignoreExternal: true
}],
'import/no-self-import': 'error',
'import/order': ['error', {
alphabetize: {
order: 'asc',
caseInsensitive: true
},
'newlines-between': 'always'
}],
'import/no-unresolved': ['error', {
commonjs: true
}],
'n/no-unsupported-features/es-builtins': 'error',
'n/no-unsupported-features/es-syntax': 'error',
'n/no-unsupported-features/node-builtins': 'error',
'n/prefer-global/buffer': ['error', 'always'],
'n/prefer-global/console': ['error', 'always'],
'n/prefer-global/process': ['error', 'always'],
'n/prefer-global/text-decoder': ['error', 'always'],
'n/prefer-global/text-encoder': ['error', 'always'],
'n/prefer-global/url': ['error', 'always'],
'n/prefer-global/url-search-params': ['error', 'always'],
'n/prefer-promises/dns': 'error',
'n/prefer-promises/fs': 'error'
}
}
14 changes: 6 additions & 8 deletions packages/eslint-config-js/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,7 @@
"version": "0.3.0",
"description": "base eslint config for js apps",
"main": "index.js",
"files": [
".eslintrc.json"
],
"files": ["standard.js"],
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1",
"lint": "eslint ."
Expand All @@ -27,11 +25,11 @@
"homepage": "https://github.com/autotelic/lint-configs/tree/main/packages/eslint-config-js",
"license": "MIT",
"dependencies": {
"@rushstack/eslint-patch": "^1.2.0",
"eslint-config-standard": "^17.0.0",
"eslint-plugin-import": "^2.27.5",
"eslint-plugin-n": "^15.6.1",
"eslint-plugin-promise": "^6.1.1"
"eslint-config-standard": "17.1.0",
"eslint-plugin-import": "^2.29.1",
"eslint-plugin-n": "^16.6.2",
"eslint-plugin-promise": "^6.1.1",
"globals": "^14.0.0"
},
"devDependencies": {
"eslint": "^8.36.0"
Expand Down
31 changes: 31 additions & 0 deletions packages/eslint-config-js/standard.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
const standard = require('eslint-config-standard')
const pluginImport = require('eslint-plugin-import')
const pluginN = require('eslint-plugin-n')
const pluginPromise = require('eslint-plugin-promise')
const globals = require('globals')

// TODO(HW13): Get `languageOptions` and `plugins` directly from eslint-config-standard
// as soon as they publish their flat config
// -> https://github.com/standard/eslint-config-standard/issues/351
module.exports = {
languageOptions: {
ecmaVersion: 2022,
sourceType: 'module',
parserOptions: {
ecmaFeatures: { jsx: true }
},
globals: {
...globals.es2021,
...globals.node,
document: 'readonly',
navigator: 'readonly',
window: 'readonly'
}
},
plugins: {
n: pluginN,
promise: pluginPromise,
import: pluginImport
},
rules: standard.rules
}
Loading

0 comments on commit 15abd48

Please sign in to comment.