Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update eslint config and dependencies #732

Draft
wants to merge 14 commits into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 0 additions & 5 deletions .eslintignore

This file was deleted.

23 changes: 0 additions & 23 deletions .eslintrc

This file was deleted.

17 changes: 7 additions & 10 deletions .github/workflows/continuous-integration.yml
Original file line number Diff line number Diff line change
Expand Up @@ -25,16 +25,13 @@ jobs:
run: yarn --immutable
- name: Build ESLint, Prettier and Utilities
run: |
yarn workspaces foreach \
--all \
--parallel \
--include @sapphire/eslint-config \
--include @sapphire/prettier-config \
--include @sapphire/eslint-plugin-result \
--include @sapphire/result \
--include @sapphire/node-utilities \
--include @sapphire/utilities \
run build
yarn turbo run build \
--filter=@sapphire/eslint-config \
--filter=@sapphire/prettier-config \
--filter=@sapphire/eslint-plugin-result \
--filter=@sapphire/result \
--filter=@sapphire/node-utilities \
--filter=@sapphire/utilities
- name: Run ESLint
run: yarn lint --fix=false

Expand Down
31 changes: 31 additions & 0 deletions eslint.config.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
import sapphireEslintConfig from './packages/eslint-config/dist/esm/index.mjs';

/**
* @type {import('@typescript-eslint/utils').TSESLint.FlatConfig.ConfigArray}
*/
const config = [
{
ignores: ['node_modules/', '**/dist/', '**/docs/', '**/*.d.ts', '**/coverage/']
},
...sapphireEslintConfig,
{
files: ['**/*.test.ts'],
rules: {
'@typescript-eslint/no-extraneous-class': 'off'
}
},
{
files: ['**/PaginatedMessage.ts'],
rules: {
'@typescript-eslint/member-ordering': 'off'
}
},
{
files: ['**/omitKeysFromObject.ts'],
rules: {
'@typescript-eslint/ban-types': 'off'
}
}
];

export default config;
10 changes: 5 additions & 5 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
"scripts": {
"clean": "node scripts/clean.mjs",
"clean:full": "node scripts/clean-full.mjs",
"lint": "eslint packages --ext mjs,js,ts,tsx --fix",
"lint": "eslint packages --fix",
"format": "prettier --ignore-path=.prettierignore --write \"packages/**/{src,tests,scripts}/**/*.{mjs,ts,js}\"",
"test": "vitest run",
"build": "yarn workspace @sapphire/node-utilities build && turbo run build",
Expand All @@ -30,14 +30,14 @@
"@types/lodash": "^4.17.4",
"@types/node": "^20.12.12",
"@types/ws": "^8.5.10",
"@typescript-eslint/eslint-plugin": "^7.10.0",
"@typescript-eslint/parser": "^7.10.0",
"@typescript-eslint/eslint-plugin": "rc-v8",
"@typescript-eslint/parser": "rc-v8",
"@vitest/coverage-v8": "^1.6.0",
"concurrently": "^8.2.2",
"cz-conventional-changelog": "^3.3.0",
"discord-api-types": "^0.37.85",
"discord.js": "^14.15.2",
"eslint": "^8.57.0",
"eslint": "^9.3.0",
"eslint-config-prettier": "^9.1.0",
"eslint-plugin-prettier": "^5.1.3",
"lint-staged": "^15.2.5",
Expand Down Expand Up @@ -70,7 +70,7 @@
},
"lint-staged": {
"*": "prettier --ignore-unknown --write",
"*.{mjs,js,ts}": "eslint --fix --ext mjs,js,ts"
"*.{mjs,js,ts}": "eslint --fix"
},
"config": {
"commitizen": {
Expand Down
2 changes: 1 addition & 1 deletion packages/async-queue/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
"homepage": "https://github.com/sapphiredev/utilities/tree/main/packages/async-queue",
"scripts": {
"test": "vitest run",
"lint": "eslint src tests --ext ts --fix -c ../../.eslintrc",
"lint": "eslint src tests --fix -c ../../eslint.config.mjs",
"docs": "typedoc-json-parser",
"build": "tsup && yarn build:rename-cjs-index",
"build:rename-cjs-index": "tsx --tsconfig ../../scripts/tsconfig.json ../../scripts/rename-cjs-index.cts",
Expand Down
2 changes: 1 addition & 1 deletion packages/bitfield/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
"homepage": "https://github.com/sapphiredev/utilities/tree/main/packages/bitfield",
"scripts": {
"test": "vitest run",
"lint": "eslint src tests --ext ts --fix -c ../../.eslintrc",
"lint": "eslint src tests --fix -c ../../eslint.config.mjs",
"build": "tsup && yarn build:rename-cjs-index",
"build:rename-cjs-index": "tsx --tsconfig ../../scripts/tsconfig.json ../../scripts/rename-cjs-index.cts",
"docs": "typedoc-json-parser",
Expand Down
2 changes: 1 addition & 1 deletion packages/cron/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
"homepage": "https://github.com/sapphiredev/utilities/tree/main/packages/cron",
"scripts": {
"test": "vitest run",
"lint": "eslint src tests --ext ts --fix -c ../../.eslintrc",
"lint": "eslint src tests --fix -c ../../eslint.config.mjs",
"build": "tsup && yarn build:rename-cjs-index",
"build:rename-cjs-index": "tsx --tsconfig ../../scripts/tsconfig.json ../../scripts/rename-cjs-index.cts",
"docs": "typedoc-json-parser",
Expand Down
2 changes: 1 addition & 1 deletion packages/decorators/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
"homepage": "https://github.com/sapphiredev/utilities/tree/main/packages/decorators",
"scripts": {
"test": "vitest run",
"lint": "eslint src tests --ext ts --fix -c ../../.eslintrc",
"lint": "eslint src tests --fix -c ../../eslint.config.mjs",
"build": "tsup && yarn build:rename-cjs-index",
"build:rename-cjs-index": "tsx --tsconfig ../../scripts/tsconfig.json ../../scripts/rename-cjs-index.cts",
"docs": "typedoc-json-parser",
Expand Down
2 changes: 1 addition & 1 deletion packages/discord-utilities/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
"homepage": "https://github.com/sapphiredev/utilities/tree/main/packages/discord-utilities",
"scripts": {
"test": "vitest run",
"lint": "eslint src --ext ts --fix -c ../../.eslintrc",
"lint": "eslint src --fix -c ../../eslint.config.mjs",
"build": "tsup && yarn build:rename-cjs-index",
"build:rename-cjs-index": "tsx --tsconfig ../../scripts/tsconfig.json ../../scripts/rename-cjs-index.cts",
"docs": "typedoc-json-parser",
Expand Down
2 changes: 1 addition & 1 deletion packages/discord.js-utilities/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
"sideEffects": false,
"homepage": "https://github.com/sapphiredev/utilities/tree/main/packages/discord.js-utilities",
"scripts": {
"lint": "eslint src --ext ts --fix -c ../../.eslintrc",
"lint": "eslint src --fix -c ../../eslint.config.mjs",
"build": "tsup && yarn build:types",
"build:types": "concurrently \"yarn:build:types:*\"",
"build:types:cjs": "rollup-type-bundler -d dist/cjs -ot .cts",
Expand Down
2 changes: 1 addition & 1 deletion packages/duration/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
"homepage": "https://github.com/sapphiredev/utilities/tree/main/packages/duration",
"scripts": {
"test": "vitest run",
"lint": "eslint src tests --ext ts --fix -c ../../.eslintrc",
"lint": "eslint src tests --fix -c ../../eslint.config.mjs",
"build": "tsup && yarn build:rename-cjs-index",
"build:rename-cjs-index": "tsx --tsconfig ../../scripts/tsconfig.json ../../scripts/rename-cjs-index.cts",
"docs": "typedoc-json-parser",
Expand Down
48 changes: 17 additions & 31 deletions packages/eslint-config/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,46 +21,31 @@ You can use the following command to install this package, or replace `npm insta
npm install --save-dev @sapphire/eslint-config
```

It is important to note that this package only exports [ESLint Flat Config][]! This means that you _have_ to use `eslint.config.js`, `eslint.config.mjs`, or `eslint.config.cjs` to use this package. See the ESLint documentation on flat config for more information.

---

## Usage

Add the ESLint config to your `package.json`:

```json
{
"name": "my-project",
"eslintConfig": {
"extends": "@sapphire"
}
}
```

Or to `eslintrc.js` / `.eslintrc.json`:
1. Create a file `eslint.config.mjs` in the root of your project.
2. Add the following content to the file:

```json
{
"extends": "@sapphire"
}
```

Or to `eslint.config.js`:

```
const { FlatCompat } = require('@eslint/eslintrc')
const sapphireEslintConfig = require('@sapphire/eslint-config')
```js
import sapphireEslintConfig from '@sapphire/eslint-config';

const compat = new FlatCompat()
/**
* @type {import('@typescript-eslint/utils').TSESLint.FlatConfig.ConfigArray}
*/
const config = [
// Additional config here
...sapphireEslintConfig
// or here
];

module.exports = [
...compat.config(sapphireEslintConfig),
{
// other configs
}
]
export default config;
```

Create `tsconfig.eslint.json` next to the eslint config file, for example with content:
3. Create `tsconfig.eslint.json` next to the eslint config file, for example with content:

```json
{
Expand Down Expand Up @@ -93,3 +78,4 @@ Thank you to all the people who already contributed to Sapphire!
</a>

[contributing]: https://github.com/sapphiredev/.github/blob/main/.github/CONTRIBUTING.md
[ESLint Flat Config]: https://eslint.org/blog/2022/08/new-config-system-part-2/
25 changes: 18 additions & 7 deletions packages/eslint-config/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,14 @@
"license": "MIT",
"main": "dist/cjs/index.cjs",
"module": "dist/esm/index.mjs",
"types": "dist/cjs/index.d.cts",
"exports": {
"import": {
"types": "./dist/esm/index.d.mts",
"default": "./dist/esm/index.mjs"
},
"require": {
"types": "./dist/cjs/index.d.cts",
"default": "./dist/cjs/index.cjs"
}
},
Expand All @@ -19,19 +22,26 @@
"scripts": {
"test": "vitest run",
"prelint": "yarn test && yarn build",
"build": "tsup",
"build": "tsup && yarn build:rename-cjs-index",
"build:rename-cjs-index": "tsx --tsconfig ../../scripts/tsconfig.json ../../scripts/rename-cjs-index.cts",
"prepack": "yarn build",
"bump": "cliff-jumper",
"check-update": "cliff-jumper --dry-run"
},
"dependencies": {
"@typescript-eslint/eslint-plugin": "^7.10.0",
"@typescript-eslint/parser": "^7.10.0",
"eslint": "^8.57.0",
"@eslint/js": "^9.3.0",
"@types/eslint-config-prettier": "^6.11.3",
"@types/eslint__js": "^8.42.3",
"@typescript-eslint/eslint-plugin": "rc-v8",
"@typescript-eslint/parser": "rc-v8",
"@typescript-eslint/utils": "rc-v8",
"eslint": "^9.3.0",
"eslint-config-prettier": "^9.1.0",
"eslint-plugin-prettier": "^5.1.3",
"globals": "^15.3.0",
"prettier": "^3.2.5",
"typescript": "^5.4.5"
"typescript": "^5.4.5",
"typescript-eslint": "rc-v8"
},
"repository": {
"type": "git",
Expand All @@ -42,8 +52,8 @@
"dist/"
],
"engines": {
"node": ">=v14.0.0",
"npm": ">=7.0.0"
"node": "^18.18.0 || ^20.9.0 || >=21.1.0",
"npm": ">=10.0.0"
},
"keywords": [
"sapphiredev",
Expand All @@ -65,6 +75,7 @@
"@favware/cliff-jumper": "^3.0.3",
"@vitest/coverage-v8": "^1.6.0",
"tsup": "^8.0.2",
"tsx": "^4.11.0",
"typedoc-json-parser": "^10.0.0",
"vitest": "^1.6.0"
}
Expand Down
Loading