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

eslint config adjustments #122

Merged
merged 9 commits into from
Dec 28, 2022
Merged
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
12 changes: 12 additions & 0 deletions .changeset/@theguild_eslint-config-122-dependencies.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
---
"@theguild/eslint-config": patch
---
dependencies updates:
- Updated dependency [`@typescript-eslint/eslint-plugin@^5.45.1` ↗︎](https://www.npmjs.com/package/@typescript-eslint/eslint-plugin/v/5.45.1) (from `^5.42.0`, in `dependencies`)
- Updated dependency [`@typescript-eslint/parser@^5.45.1` ↗︎](https://www.npmjs.com/package/@typescript-eslint/parser/v/5.45.1) (from `^5.42.0`, in `dependencies`)
- Updated dependency [`eslint-plugin-n@^15.6.0` ↗︎](https://www.npmjs.com/package/eslint-plugin-n/v/15.6.0) (from `^15.4.0`, in `dependencies`)
- Updated dependency [`eslint-plugin-unicorn@^45.0.1` ↗︎](https://www.npmjs.com/package/eslint-plugin-unicorn/v/45.0.1) (from `^45.0.0`, in `dependencies`)
- Added dependency [`eslint-plugin-jsx-a11y@^6.6.1` ↗︎](https://www.npmjs.com/package/eslint-plugin-jsx-a11y/v/6.6.1) (to `dependencies`)
- Added dependency [`eslint-plugin-mdx@^2.0.5` ↗︎](https://www.npmjs.com/package/eslint-plugin-mdx/v/2.0.5) (to `dependencies`)
- Added dependency [`eslint-plugin-react@^7.31.11` ↗︎](https://www.npmjs.com/package/eslint-plugin-react/v/7.31.11) (to `dependencies`)
- Added dependency [`eslint-plugin-react-hooks@^4.6.0` ↗︎](https://www.npmjs.com/package/eslint-plugin-react-hooks/v/4.6.0) (to `dependencies`)
5 changes: 5 additions & 0 deletions .changeset/wise-pears-impress.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@theguild/eslint-config': minor
---

run react rule on js/ts files, since it can be react hook without JSX extension
7 changes: 6 additions & 1 deletion .eslintrc.cjs
Original file line number Diff line number Diff line change
@@ -1,5 +1,10 @@
module.exports = {
extends: ['@theguild', '@theguild/eslint-config/mdx'],
extends: [
'@theguild',
'@theguild/eslint-config/json',
'@theguild/eslint-config/yml',
'@theguild/eslint-config/mdx',
],
env: {
node: true,
},
Expand Down
6 changes: 3 additions & 3 deletions readme.md → README.md
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ Make sure to adjust you Changesets config file, based on your repo setup:
{
"$schema": "https://unpkg.com/@changesets/config@2.1.0/schema.json",
"changelog": [
"@changesets/changelog-github", // this will make nice output for changesets, with "thank you..." notes, and liks to the commits + references in PRs!
"@changesets/changelog-github", // this will make nice output for changesets, with "thank you..." notes, and links to the commits + references in PRs!
{ "repo": "guild-member/project-repo" } // Set the repo name here
],
"commit": false,
Expand Down Expand Up @@ -333,13 +333,13 @@ If Prettier or other tools are used, ensure to exclude the `website/algolia-lock

3. Add Algolia credentials to repo secrets

Configure the following Github Actions secrets from your Algolia dashboard:
Configure the following GitHub Actions secrets from your Algolia dashboard:

- `ALGOLIA_APP_ID`
- `ALGOLIA_ADMIN_API_KEY`
- `ALGOLIA_INDEX_NAME`

4. Add the Github Actions workflows
4. Add the GitHub Actions workflows

_PR workflow example_

Expand Down
6 changes: 6 additions & 0 deletions cspell.config.cjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
module.exports = {
language: 'en',
import: ['@theguild/eslint-config/cspell.config'],
words: [],
ignorePaths: ['./patches/*.patch', './pnpm-lock.yaml'],
};
7 changes: 4 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,8 @@
"license": "MIT",
"private": true,
"scripts": {
"build": "echo No build command, skipping...",
"build": "echo No build command, skipping…",
"cspell": "cspell --gitignore **/*",
"lint": "eslint --ignore-path .gitignore .",
"lint:prettier": "prettier --ignore-path .gitignore --check .",
"lint:remote": "eslint-remote-tester",
Expand All @@ -23,9 +24,9 @@
"@theguild/eslint-config": "workspace:*",
"@theguild/prettier-config": "workspace:*",
"@types/eslint": "8.4.10",
"@types/node": "18.11.17",
"@types/node": "18.11.18",
"cspell": "6.17.0",
"eslint": "8.30.0",
"eslint-plugin-n": "15.6.0",
"eslint-remote-tester": "3.0.0",
"patch-package": "6.5.0",
"prettier": "2.8.1",
Expand Down
66 changes: 66 additions & 0 deletions packages/eslint-config/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
# @theguild/eslint-config

Guild's ESLint shareable configs for linting JavaScript/TypeScript/React projects.

## Install

For JavaScript/TypeScript projects

```sh
pnpm add -D eslint @theguild/eslint-config
```

## Usage

Extend a `@theguild` config for JavaScript/TypeScript projects.

```js
// .eslintrc.cjs
module.exports = {
extends: ['@theguild']
}
```

### React Config

Extend a `@theguild/eslint-config/react` config for React projects.

```js
// .eslintrc.cjs
module.exports = {
extends: ['@theguild/eslint-config/react']
}
```

### MDX/Markdown Config

Extend a `@theguild/eslint-config/mdx` config for `.md`/`.mdx` files.

```js
// .eslintrc.cjs
module.exports = {
extends: ['@theguild/eslint-config/mdx']
}
```

### JSON Config

Extend a `@theguild/eslint-config/json` config for `.json`/`.jsonc`/`.json5` files.

```js
// .eslintrc.cjs
module.exports = {
extends: ['@theguild/eslint-config/json']
}
```

### YAML Config

Extend a `@theguild/eslint-config/yml` config for `.yml`/`.yaml` files.

```js
// .eslintrc.cjs
module.exports = {
extends: ['@theguild/eslint-config/yml']
}
```
14 changes: 6 additions & 8 deletions packages/eslint-config/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -24,22 +24,20 @@
},
"dependencies": {
"@rushstack/eslint-patch": "^1.2.0",
"@typescript-eslint/eslint-plugin": "^5.42.0",
"@typescript-eslint/parser": "^5.42.0",
"@typescript-eslint/eslint-plugin": "^5.45.1",
"@typescript-eslint/parser": "^5.45.1",
"eslint-config-prettier": "^8.5.0",
"eslint-plugin-import": "^2.26.0",
"eslint-plugin-jsonc": "^2.5.0",
"eslint-plugin-n": "^15.4.0",
"eslint-plugin-n": "^15.6.0",
"eslint-plugin-promise": "^6.1.1",
"eslint-plugin-simple-import-sort": "^8.0.0",
"eslint-plugin-sonarjs": "^0.17.0",
"eslint-plugin-unicorn": "^45.0.0",
"eslint-plugin-yml": "^1.2.0"
},
"optionalDependencies": {
"eslint-plugin-unicorn": "^45.0.1",
"eslint-plugin-yml": "^1.2.0",
"eslint-plugin-jsx-a11y": "^6.6.1",
"eslint-plugin-mdx": "^2.0.5",
"eslint-plugin-react": "^7.31.10",
"eslint-plugin-react": "^7.31.11",
"eslint-plugin-react-hooks": "^4.6.0"
},
"publishConfig": {
Expand Down
42 changes: 0 additions & 42 deletions packages/eslint-config/readme.md

This file was deleted.

6 changes: 4 additions & 2 deletions packages/eslint-config/src/base.js
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,6 @@ const SORT_IMPORTS_GROUPS = [
.join('|')})(/.*|$)`,
'^react(-dom)?$',
'^next(/.*|$)',
'^graphql(/.*|$)',
// Packages.
// Things that start with a letter (or digit or underscore), or `@` followed by a letter.
'^@?\\w',
Expand All @@ -54,6 +53,7 @@ const SORT_IMPORTS_GROUPS = [
// Relative imports.
// Anything that starts with a dot.
'^\\.',
'^.+\\.graphql',
// Style imports.
'^.+\\.css$',
],
Expand Down Expand Up @@ -104,7 +104,6 @@ module.exports = {
'import/extensions': ['error', 'ignorePackages'], // Bob when bundling requires to have `.js` extension
'import/no-default-export': 'error',
'import/prefer-default-export': 'off', // disable opposite of 'import/no-default-export'
'unicorn/filename-case': 'error',

'@typescript-eslint/no-unused-vars': ['error', { argsIgnorePattern: '^_' }],

Expand Down Expand Up @@ -146,6 +145,9 @@ module.exports = {
// Enforce consistent returning of awaited values.
// https://typescript-eslint.io/rules/return-await/
// '@typescript-eslint/return-await': 'error', // TODO: enable

'import/no-duplicates': 'error',
'import/newline-after-import': 'error',
},
};

Expand Down
4 changes: 4 additions & 0 deletions packages/eslint-config/src/constants.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
module.exports = {
CODE_BLOCK: '**/*.md{,x}/*',
CODE_FILE: '*.{,c,m}{j,t}s{,x}'
}
49 changes: 49 additions & 0 deletions packages/eslint-config/src/cspell.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
const ignoreWords = [
// libraries
'clsx',
'cssnano',
'tailwindcss',
'Nextra',
'tsup',
'sonarjs',
'CodeGen',
'GitHunt',
'pnpm',
'rushstack',
'supertokens',
'turborepo',
'esbuild',
'dockest',
'clickhouse',
'pulumi',
'slonik',

// users
'kamil',
'theguild',
'kamilkisiela',
'urigo',
'ardatan',
'maticzav',
'dimatill',
'dotansimha',
'saihaj',

// valid spellings
'rediscuss',
'styleguide',
'automerge',
'ingestor',
'testkit',
'sourcemaps',

// others
'cjsx',
'mjsx',
'ctsx',
'mtsx',
];

module.exports = {
ignoreWords,
};
11 changes: 10 additions & 1 deletion packages/eslint-config/src/index.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
const { CODE_FILE, CODE_BLOCK } = require('./constants.js');

require('@rushstack/eslint-patch/modern-module-resolution');

module.exports = {
Expand All @@ -8,9 +10,16 @@ module.exports = {
],
overrides: [
{
files: '*.{,c,m}{j,t}s{,x}',
files: CODE_FILE,
extends: './base',
},
{
files: CODE_FILE,
excludedFiles: CODE_BLOCK,
rules: {
'unicorn/filename-case': 'error',
}
},
{
files: ['*.c{j,t}s'],
env: { node: true },
Expand Down
3 changes: 3 additions & 0 deletions packages/eslint-config/src/json.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
const { CODE_BLOCK } = require('./constants.js');

const JSONC_FILES = ['tsconfig.json', 'tsconfig.eslint.json', 'turbo.json'];

module.exports = {
Expand All @@ -17,6 +19,7 @@ module.exports = {
},
{
files: '*.json{,c,5}',
excludedFiles: CODE_BLOCK,
plugins: ['unicorn'],
rules: {
'unicorn/filename-case': 'error',
Expand Down
14 changes: 9 additions & 5 deletions packages/eslint-config/src/mdx.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
const { CODE_BLOCK } = require('./constants.js');

module.exports = {
// Extending follow configs to lint code blocks content by their virtual filenames
extends: ['./react', './json', './yml'],
overrides: [
{
files: '*.md{,x}',
Expand All @@ -23,17 +23,21 @@ module.exports = {
// Disable filename check
{
files: [
'**/*.md{,x}/*', // Redundant, in first override rule already compare filename
CODE_BLOCK,
'.changeset/*.md',
'CHANGELOG.md',
'.github/workflows/pull_request_template.md',
'SECURITY.md',
'CODE_OF_CONDUCT.md',
'README.md',
],
rules: {
'unicorn/filename-case': 'off',
},
},
// Disable code-file rules inside md/mdx
// Disable rules for code blocks
{
files: ['**/*.md{,x}/*'],
files: [CODE_BLOCK],
rules: {
'no-console': 'off',
'@typescript-eslint/no-unused-vars': 'off',
Expand Down
Loading