Skip to content

Commit

Permalink
Merge pull request #3 from eduzz/support-flat-config
Browse files Browse the repository at this point in the history
Support flat config
  • Loading branch information
danieloprado authored Jun 3, 2024
2 parents 13efbd8 + 214a757 commit 8a15a69
Show file tree
Hide file tree
Showing 14 changed files with 1,203 additions and 2,283 deletions.
4 changes: 0 additions & 4 deletions .eslintrc

This file was deleted.

2 changes: 1 addition & 1 deletion .github/CODEOWNERS
Validating CODEOWNERS rules …
Original file line number Diff line number Diff line change
@@ -1 +1 @@
* @danieloprado @ffernandomoraes @JonathasRodrigues
* @danieloprado @ffernandomoraes @JonathasRodrigues @caferrari @henriquegomes6
28 changes: 15 additions & 13 deletions .prettierrc.js
Original file line number Diff line number Diff line change
@@ -1,14 +1,16 @@
module.exports = {
"singleQuote": true,
"jsxSingleQuote": true,
"quoteProps": "consistent",
"trailingComma": "none",
"useTabs": false,
"tabWidth": 2,
"bracketSpacing": true,
"bracketSameLine": false,
"arrowParens": "avoid",
"endOfLine": "lf",
"printWidth": 120,
"semi": true
}
singleQuote: true,
jsxSingleQuote: true,
quoteProps: 'consistent',
trailingComma: 'none',
useTabs: false,
tabWidth: 2,
bracketSpacing: true,
bracketSameLine: false,
arrowParens: 'avoid',
endOfLine: 'auto',
printWidth: 120,
semi: true,
plugins: ['prettier-plugin-tailwindcss'],
tailwindFunctions: ['tw', 'clsx']
};
64 changes: 14 additions & 50 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,75 +2,39 @@

Configuração padrão do eslint para os projetos da Eduzz.

## Migração

Se está migrando do `@eduzz/eslint-config-houston` altere as configurações do `.eslintrc [extends]` para:

* `@eduzz/eslint-config-houston` >> `@eduzz/eslint-config/react`
* `@eduzz/eslint-config-houston/native` >> `@eduzz/eslint-config/react-native`
* `@eduzz/eslint-config-houston/node` >> `@eduzz/eslint-config`

## Instalação

Para configurar no padrão da Eduzz, primerio você deve adicionar as dependências, pois o eslint exige que plugins devem,
ser adicionados no projeto principal

### Javascript / Typescript / Node

```sh
yarn add --dev @eduzz/eslint-config eslint @typescript-eslint/eslint-plugin @typescript-eslint/parser eslint-config-prettier eslint-plugin-eslint-plugin eslint-plugin-import eslint-plugin-prettier eslint-plugin-unused-imports prettier
yarn add --dev @eduzz/eslint-config
```

1. `eslint.config.js`
```js
// .eslintrc
{
"extends": ["@eduzz/eslint-config"]
}
const { ignores, configs } = require('@eduzz/eslint-config'); // Javascript / Typescript / Node
const { ignores, configs } = require('@eduzz/eslint-config/react'); // React
const { ignores, configs } = require('@eduzz/eslint-config/react-native'); // React Native

// .prettierrc.js
module.exports = {
...require('@eduzz/eslint-config/.prettierrc')
};
/** @type import('eslint').Linter.FlatConfig[] */
module.exports = [...configs, { ignores: ignores() }];
```

### React

```sh
yarn add --dev @eduzz/eslint-config eslint @typescript-eslint/eslint-plugin @typescript-eslint/parser eslint-config-prettier eslint-plugin-eslint-plugin eslint-plugin-import eslint-plugin-prettier eslint-plugin-react eslint-plugin-react-hooks eslint-plugin-unused-imports prettier
```

2. `.prettierrc.js`
```js
// .eslintrc
{
"extends": ["@eduzz/eslint-config/react"]
}

// .prettierrc.js
module.exports = {
...require('@eduzz/eslint-config/.prettierrc')
};
```

### React Native
## Configurações Extras

```sh
yarn add --dev @eduzz/eslint-config eslint eslint-plugin-react-native @typescript-eslint/eslint-plugin @typescript-eslint/parser eslint-config-prettier eslint-plugin-eslint-plugin eslint-plugin-import eslint-plugin-prettier eslint-plugin-react eslint-plugin-react-hooks eslint-plugin-unused-imports prettier
```
### Ignore

```js
// .eslintrc
{
"extends": ["@eduzz/eslint-config/react-native"]
}
Por padrão todos os arquivos do `.gitignore` já são removidos, caso queira adicionar mais:

// .prettierrc.js
module.exports = {
...require('@eduzz/eslint-config/.prettierrc')
};
```js
/** @type import('eslint').Linter.FlatConfig[] */
module.exports = [...configs, { ignores: ignores('**/ignore/**.js', 'ignore.js') }];
```

## Configurações Extras

### VSCode

- Adicione a extensão do [ESLint](https://marketplace.visualstudio.com/items?itemName=dbaeumer.vscode-eslint).
Expand Down
41 changes: 25 additions & 16 deletions configs/default.js
Original file line number Diff line number Diff line change
@@ -1,15 +1,26 @@
const pluginImport = require('eslint-plugin-import');
const pluginPrettier = require('eslint-plugin-prettier');

/** @type import('eslint').Linter.FlatConfig */
module.exports = {
name: '@eduzz/eslint-config-defaults',
settings: {
'import/internal-regex': '(^@eduzz|react|^@nestjs|^~)'
},
plugins: ['prettier', 'eslint-plugin-unused-imports'],
extends: ['plugin:prettier/recommended', 'plugin:import/recommended', 'plugin:import/typescript'],
parserOptions: {
ecmaVersion: 10,
sourceType: 'module',
ecmaFeatures: { modules: true, jsx: true }
plugins: {
prettier: pluginPrettier,
import: pluginImport
},
languageOptions: {
parserOptions: {
ecmaVersion: 10,
sourceType: 'module',
ecmaFeatures: { modules: true, jsx: true }
}
},
rules: {
...pluginPrettier.configs.recommended.rules,
...pluginImport.configs.recommended.rules,
'no-restricted-globals': ['error'],
'object-shorthand': ['error', 'always', { avoidQuotes: true }],
'padding-line-between-statements': [
Expand All @@ -31,7 +42,13 @@ module.exports = {
'@mui/system',
'@mui/styles'
],
'linebreak-style': ['error', 'unix'],
'no-restricted-syntax': [
'error',
{
selector: 'VariableDeclarator > Identifier[name=/^process/i]',
message: 'process is a reserved name for NodeJS Enviroment'
}
],
'max-lines': ['error', 300],
'max-len': ['off'],
'no-multiple-empty-lines': ['error', { max: 1 }],
Expand All @@ -43,7 +60,6 @@ module.exports = {
'eqeqeq': 0,
'quote-props': 'off',
'no-useless-escape': 'off',
'unused-imports/no-unused-imports-ts': 'error',
'import/no-unresolved': 'off',
'import/named': 'off',
'import/namespace': 'off',
Expand All @@ -53,7 +69,6 @@ module.exports = {
'import/no-cycle': 'off',
'import/no-deprecated': 'off',
'import/no-unused-modules': 'off',
'import/newline-after-import': 'error',
'import/first': 'error',
'import/order': [
'error',
Expand All @@ -75,11 +90,5 @@ module.exports = {
]
}
]
},
overrides: [
{
files: '*.mdx',
rules: {}
}
]
}
};
12 changes: 10 additions & 2 deletions configs/react.js
Original file line number Diff line number Diff line change
@@ -1,10 +1,18 @@
const pluginReact = require('eslint-plugin-react');
const pluginReactHooks = require('eslint-plugin-react-hooks');

/** @type import('eslint').Linter.FlatConfig */
module.exports = {
name: '@eduzz/eslint-config-react',
settings: {
react: { version: 'detect' }
},
plugins: ['react', 'react-hooks'],
extends: ['plugin:react/recommended'],
plugins: {
'react': pluginReact,
'react-hooks': pluginReactHooks
},
rules: {
...pluginReact.configs.recommended.rules,
'react/display-name': ['off'],
'react/prop-types': ['off'],
'react/no-unescaped-entities': ['off'],
Expand Down
105 changes: 57 additions & 48 deletions configs/typescript.js
Original file line number Diff line number Diff line change
@@ -1,49 +1,58 @@
module.exports = {
extends: ['plugin:@typescript-eslint/recommended'],
rules: {
'no-unused-vars': 'off',
'@typescript-eslint/no-unused-vars': [
'warn',
{
argsIgnorePattern: '^_',
varsIgnorePattern: '^_',
caughtErrorsIgnorePattern: '^_'
}
],
'@typescript-eslint/adjacent-overload-signatures': ['error'],
'@typescript-eslint/naming-convention': [
'error',
{
selector: 'variable',
format: ['camelCase', 'UPPER_CASE', 'PascalCase'],
leadingUnderscore: 'allowSingleOrDouble'
},
{
selector: 'parameter',
format: ['camelCase', 'PascalCase'],
leadingUnderscore: 'allow'
},
{
selector: 'memberLike',
modifiers: ['private'],
format: ['camelCase'],
leadingUnderscore: 'allowSingleOrDouble'
},
{
selector: 'typeLike',
format: ['camelCase', 'PascalCase']
}
],
'@typescript-eslint/member-ordering': ['error'],
'@typescript-eslint/no-namespace': ['error'],
'@typescript-eslint/no-require-imports': ['error'],
'@typescript-eslint/no-object-literal-type-assertion': 'off',
'@typescript-eslint/no-useless-constructor': 'error',
'@typescript-eslint/no-empty-interface': 'off',
'@typescript-eslint/explicit-function-return-type': 'off',
'@typescript-eslint/no-var-requires': 'off',
'@typescript-eslint/no-explicit-any': 'off',
'@typescript-eslint/explicit-module-boundary-types': 'off',
'@typescript-eslint/explicit-member-accessibility': ['error', { overrides: { constructors: 'no-public' } }]
const pluginImport = require('eslint-plugin-import');
const tseslint = require('typescript-eslint');

/** @type import('eslint').Linter.FlatConfig */
module.exports = [
...tseslint.configs.recommended.map(config => ({ ...config, files: ['**/*.ts', '**/*.tsx'] })),
{
name: '@eduzz/eslint-config-typescript',
files: ['**/*.ts', '**/*.tsx'],
rules: {
...pluginImport.configs.typescript.rules,
'no-unused-vars': 'off',
'@typescript-eslint/no-unused-vars': [
'warn',
{
argsIgnorePattern: '^_',
varsIgnorePattern: '^_',
caughtErrorsIgnorePattern: '^_'
}
],
'@typescript-eslint/adjacent-overload-signatures': ['error'],
'@typescript-eslint/naming-convention': [
'error',
{
selector: 'variable',
format: ['camelCase', 'UPPER_CASE', 'PascalCase'],
leadingUnderscore: 'allowSingleOrDouble'
},
{
selector: 'parameter',
format: ['camelCase', 'PascalCase'],
leadingUnderscore: 'allow'
},
{
selector: 'memberLike',
modifiers: ['private'],
format: ['camelCase'],
leadingUnderscore: 'allowSingleOrDouble'
},
{
selector: 'typeLike',
format: ['camelCase', 'PascalCase']
}
],
'@typescript-eslint/member-ordering': ['error'],
'@typescript-eslint/no-namespace': ['error'],
'@typescript-eslint/no-require-imports': ['error'],
'@typescript-eslint/no-object-literal-type-assertion': 'off',
'@typescript-eslint/no-useless-constructor': 'error',
'@typescript-eslint/no-empty-interface': 'off',
'@typescript-eslint/explicit-function-return-type': 'off',
'@typescript-eslint/no-var-requires': 'off',
'@typescript-eslint/no-explicit-any': 'off',
'@typescript-eslint/explicit-module-boundary-types': 'off',
'@typescript-eslint/explicit-member-accessibility': ['error', { overrides: { constructors: 'no-public' } }]
}
}
};
];
1 change: 1 addition & 0 deletions eslint.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
module.exports = require('./configs/default');
35 changes: 35 additions & 0 deletions ignores.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
const childProcess = require('child_process');
const fs = require('node:fs');

const parse = require('parse-gitignore');

module.exports = function gitignore(...extra) {
const files = childProcess
.execSync('git ls-files *.gitignore')
.toString()
.split('\n')
.filter(file => !!file);

const ignores = [];

for (const file of files) {
let content = '';

try {
content = fs.readFileSync(file, 'utf8');
} catch (error) {
continue;
}

const parsed = parse(`${content}\n`);
const globs = parsed.globs();
console.log(JSON.stringify(globs, null, 2));

for (const glob of globs) {
if (glob.type === 'ignore') ignores.push(...glob.patterns);
else if (glob.type === 'unignore') ignores.push(...glob.patterns.map(pattern => `!${pattern}`));
}
}

return [...ignores, ...extra];
};
9 changes: 7 additions & 2 deletions index.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,9 @@
const configDefault = require('./configs/default');
const configTypescript = require('./configs/typescript');
const ignores = require('./ignores');

module.exports = {
extends: ['./configs/default', './configs/typescript'],
env: { node: true }
ignores,
/** @type import('eslint').Linter.FlatConfig[] */
configs: [configDefault, ...configTypescript]
};
Loading

0 comments on commit 8a15a69

Please sign in to comment.