Coding convention like Prettier and ESLint #1201
Replies: 3 comments 7 replies
-
Let's start with React/ESLint. Here's a basic proposal with detailed file and handler function naming conventions, as well as React-specific rules. module.exports = {
root: true,
env: {
browser: true,
es2021: true,
node: true,
},
settings: {
react: {
version: 'detect',
},
},
ignorePatterns: ['dist', '.eslintrc.cjs', 'prettier.config.cjs'],
extends: [
'eslint:recommended',
'plugin:@typescript-eslint/recommended',
'plugin:unicorn/recommended',
'plugin:react/recommended',
'plugin:react/jsx-runtime',
'plugin:react-hooks/recommended',
],
plugins: ['@typescript-eslint', 'react'],
parser: '@typescript-eslint/parser',
parserOptions: {
project: ['./tsconfig.json', './tsconfig.node.json'],
},
rules: {
'no-console': 2,
eqeqeq: 2,
},
overrides: [
{
files: ['**/*.{jsx,ts,tsx}'],
rules: {
'react/jsx-pascal-case': 2,
'@typescript-eslint/naming-convention': [
2,
{
selector: 'variable',
format: ['camelCase', 'UPPER_CASE'],
},
{
selector: 'variable',
types: ['boolean'],
format: ['PascalCase'],
prefix: ['is', 'has', 'did', 'will', 'can', 'should'],
},
{
selector: ['variable', 'function'],
types: ['function'],
format: ['camelCase', 'StrictPascalCase'],
},
{
selector: ['interface', 'typeLike'],
format: ['PascalCase'],
},
],
'react/jsx-handler-names': [
2,
{
eventHandlerPrefix: 'handle',
eventHandlerPropPrefix: 'on',
checkLocalVariables: false,
checkInlineFunction: false,
},
],
'react/jsx-filename-extension': [2, { extensions: ['.tsx'] }],
'react/destructuring-assignment': [2, 'always'],
'react/hook-use-state': [2, { allowDestructuredState: false }],
'react/jsx-props-no-spreading': 2,
'react/no-unstable-nested-components': 2,
'react/prefer-stateless-function': 2,
'react/jsx-no-useless-fragment': 2,
'react/forbid-component-props': 2,
'unicorn/prevent-abbreviations': [
'error',
{
allowList: {
Props: true,
},
},
],
},
},
],
}; |
Beta Was this translation helpful? Give feedback.
-
@ptrkdan @jinmayamashita I think we can take a look at Biome. In all-in-one toolchain trending, it is a tool that is so good about both DX and performance. With Biome, we can simply run BenchmarkBelow is benchmark result for formatting and linting task. You can see details here Formatting
Linting
|
Beta Was this translation helpful? Give feedback.
-
@mvn-tiennguyen-hn FYI @ptrkdan Biome is a really fresh tool. They have only released version 1.0.0 and it's been less than a year. Although its history is much shorter compared to the eslint/prettier empire, I think their overwhelming performance (probably made with Rust) and the active community are strengths. Here are some things I liked after trying out Biome:
The config was easier than I expected. {
"$schema": "https://biomejs.dev/schemas/1.5.3/schema.json",
"organizeImports": {
"enabled": true
},
"formatter": {
"enabled": true,
"formatWithErrors": false,
"indentStyle": "space",
"indentWidth": 2,
"lineWidth": 80,
"lineEnding": "lf",
"ignore": []
},
"linter": {
"enabled": true,
"rules": {
"recommended": true,
"nursery": {
"useFilenamingConvention": {
"level": "error",
"options": {
"filenameCases": ["kebab-case"]
}
}
},
"style": {
"useBlockStatements": "error",
"useShorthandArrayType": "error",
"noShoutyConstants": "warn"
}
}
}
} However, there are a few minor complaints:
🤔 💭 First, let's solidify the rules for eslint/prettier and then see how well Biome can cover them. If it can cover the important rules, transitioning should not be a problem. 👍🏻 |
Beta Was this translation helpful? Give feedback.
-
The topic aims to engage in a discussion regarding the suitability of various coding conventions, such as Prettier and ESLint rules, within our projects.
The conditions for concluding the discussion are as follows: determining the rules, specifying who will create pull requests and until when.
Beta Was this translation helpful? Give feedback.
All reactions