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

[wip] refactor to use flat config #431

Draft
wants to merge 2 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
6 changes: 6 additions & 0 deletions .changeset/@theguild_eslint-config-431-dependencies.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
---
"@theguild/eslint-config": patch
---
dependencies updates:
- Removed dependency [`@rushstack/eslint-patch@^1.6.1` ↗︎](https://www.npmjs.com/package/@rushstack/eslint-patch/v/1.6.1) (from `dependencies`)
- Updated dependency [`eslint@^9` ↗︎](https://www.npmjs.com/package/eslint/v/9.0.0) (from `^8`, in `peerDependencies`)
5 changes: 5 additions & 0 deletions .changeset/few-pianos-decide.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@theguild/eslint-config": minor
---

refactor to use flat config
5 changes: 2 additions & 3 deletions packages/eslint-config/package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "@theguild/eslint-config",
"version": "0.11.8",
"type": "commonjs",
"type": "module",
"description": "The Guild's shared ESLint config",
"repository": {
"url": "the-guild-org/shared-config",
Expand All @@ -20,11 +20,10 @@
"eslint-config"
],
"peerDependencies": {
"eslint": "^8",
"eslint": "^9",
"typescript": "^5"
},
"dependencies": {
"@rushstack/eslint-patch": "^1.6.1",
"@typescript-eslint/eslint-plugin": "^7.0.0",
"@typescript-eslint/parser": "^7.0.0",
"eslint-config-prettier": "^9.1.0",
Expand Down
4 changes: 2 additions & 2 deletions packages/eslint-config/src/base.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
const { RESTRICTED_SYNTAX, RESTRICTED_GLOBALS, RESTRICTED_MODULES } = require('./constants.js');
import { RESTRICTED_GLOBALS, RESTRICTED_MODULES, RESTRICTED_SYNTAX } from './constants.js';

/** @type {import('eslint').Linter.Config} */
module.exports = {
export default {
parser: '@typescript-eslint/parser',
extends: ['eslint:recommended', 'plugin:@typescript-eslint/recommended', 'prettier'],
plugins: ['sonarjs', 'unicorn', 'promise', 'import', 'n'],
Expand Down
20 changes: 7 additions & 13 deletions packages/eslint-config/src/constants.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
const RESTRICTED_SYNTAX = [
export const RESTRICTED_SYNTAX = [
{
// ❌ readFile(…, { encoding: … })
selector: `CallExpression[callee.name=/readFileSync|readFile|writeFileSync|writeFile/] > .arguments:last-child[type=ObjectExpression][properties.length=1] Property[key.name=encoding]`,
Expand Down Expand Up @@ -46,7 +46,7 @@ const RESTRICTED_SYNTAX = [
// },
];

const REACT_RESTRICTED_SYNTAX = [
export const REACT_RESTRICTED_SYNTAX = [
...RESTRICTED_SYNTAX,
{
// ❌ useMemo(…, [])
Expand All @@ -57,9 +57,9 @@ const REACT_RESTRICTED_SYNTAX = [
},
];

const RESTRICTED_GLOBALS = ['stop', { name: 'isNaN', message: 'Use Number.isNaN instead' }];
export const RESTRICTED_GLOBALS = ['stop', { name: 'isNaN', message: 'Use Number.isNaN instead' }];

const RESTRICTED_MODULES = [
export const RESTRICTED_MODULES = [
{ name: 'axios', message: 'Use `fetch/node-fetch` instead.' },
{ name: 'moment', message: 'Use `dayjs/date-fns` instead.' },
{ name: 'classnames', message: 'Use `clsx` instead because he is faster.' },
Expand All @@ -70,12 +70,6 @@ const RESTRICTED_MODULES = [
{ name: 'lodash/identity.js', message: 'Use `(value) => value` instead.' },
];

module.exports = {
CODE_BLOCK: '**/*.md{,x}/*',
CODE_FILE: '*.{,c,m}{j,t}s{,x}',
TS_FILE: '*.{,c,m}ts{,x}',
RESTRICTED_GLOBALS,
RESTRICTED_MODULES,
RESTRICTED_SYNTAX,
REACT_RESTRICTED_SYNTAX,
};
export const CODE_BLOCK = '**/*.md{,x}/*';
export const CODE_FILE = '*.{,c,m}{j,t}s{,x}';
export const TS_FILE = '*.{,c,m}ts{,x}';
6 changes: 1 addition & 5 deletions packages/eslint-config/src/cspell.config.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
const ignoreWords = [
export const ignoreWords = [
// libraries
'clsx',
'cssnano',
Expand Down Expand Up @@ -43,7 +43,3 @@ const ignoreWords = [
'ctsx',
'mtsx',
];

module.exports = {
ignoreWords,
};
6 changes: 2 additions & 4 deletions packages/eslint-config/src/index.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,7 @@
const { CODE_FILE, TS_FILE, CODE_BLOCK } = require('./constants.js');

require('@rushstack/eslint-patch/modern-module-resolution');
import { CODE_BLOCK, CODE_FILE, TS_FILE } from './constants.js';

/** @type {import('eslint').Linter.Config} */
module.exports = {
export default {
reportUnusedDisableDirectives: true,
ignorePatterns: [
'!.*', // Don't ignore dot-files because by default ESLint ignore dot-files (except for .eslintrc.*) and dot-folders
Expand Down
4 changes: 2 additions & 2 deletions packages/eslint-config/src/json.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
const { CODE_BLOCK } = require('./constants.js');
import { CODE_BLOCK } from './constants.js';

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

/** @type {import('eslint').Linter.Config} */
module.exports = {
export default {
overrides: [
{
files: '*.json',
Expand Down
4 changes: 2 additions & 2 deletions packages/eslint-config/src/mdx.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
const { CODE_BLOCK } = require('./constants.js');
import { CODE_BLOCK } from './constants.js';

/** @type {import('eslint').Linter.Config} */
module.exports = {
export default {
overrides: [
{
files: '*.md{,x}',
Expand Down
4 changes: 2 additions & 2 deletions packages/eslint-config/src/react-base.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
const { REACT_RESTRICTED_SYNTAX } = require('./constants.js');
import { REACT_RESTRICTED_SYNTAX } from './constants.js';

const RESTRICTED_IMPORTS = [
{
Expand All @@ -15,7 +15,7 @@ const RESTRICTED_IMPORTS = [
];

/** @type {import('eslint').Linter.Config} */
module.exports = {
export default {
settings: {
react: {
version: 'detect',
Expand Down
4 changes: 2 additions & 2 deletions packages/eslint-config/src/react.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
const { CODE_FILE } = require('./constants.js');
import { CODE_FILE } from './constants.js';

/** @type {import('eslint').Linter.Config} */
module.exports = {
export default {
ignorePatterns: ['next-env.d.ts'],
overrides: [
{
Expand Down
4 changes: 2 additions & 2 deletions packages/eslint-config/src/yml.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
const { CODE_BLOCK } = require('./constants.js');
import { CODE_BLOCK } from './constants.js';

/** @type {import('eslint').Linter.Config} */
module.exports = {
export default {
ignorePatterns: ['pnpm-lock.yaml'],
overrides: [
{
Expand Down
Loading