dukDukz
React) vite + react (js) + eslint 본문
vite 설치
yarn create vite
설치 가이드대로 설치
eslint 설치
yarn add -D eslint vite-plugin-eslint eslint-config-react-app
설치하고 vscode relaod 필요함
vite.config.js
import { defineConfig } from 'vite';
import react from '@vitejs/plugin-react';
import eslint from 'vite-plugin-eslint';
// https://vitejs.dev/config/
export default defineConfig({
plugins: [react(), eslint()],
});
.eslintrc.cjs
rules 부분
module.exports = {
env: {
browser: true,
es2021: true,
node: true,
},
extends: [
'plugin:react/recommended',
'airbnb',
],
overrides: [
],
parserOptions: {
ecmaVersion: 'latest',
sourceType: 'module',
},
plugins: [
'react',
],
rules: {
indent: ['error', 2],
'no-trailing-spaces': 'error',
curly: 'error',
'brace-style': 'error',
'no-unused-vars': 1,
'no-multi-spaces': 'error',
'space-infix-ops': 'error',
'space-unary-ops': 'error',
'react/react-in-jsx-scope': 'off',
'no-whitespace-before-property': 'error',
'func-call-spacing': 'error',
'space-before-blocks': 'error',
'keyword-spacing': ['error', { before: true, after: true }],
'comma-spacing': ['error', { before: false, after: true }],
'comma-style': ['error', 'last'],
'comma-dangle': ['error', 'always-multiline'],
'space-in-parens': ['error', 'never'],
'block-spacing': 'error',
'array-bracket-spacing': ['error', 'never'],
'object-curly-spacing': ['error', 'always'],
'key-spacing': ['error', { mode: 'strict' }],
'arrow-spacing': ['error', { before: true, after: true }],
'react/require-default-props': [2, { functions: 'defaultArguments' }],
'import/prefer-default-export': 'off',
'no-console': import.meta.env.VITE_MODE === 'production' ? 'error' : 'off',
'import/no-extraneous-dependencies': ['error', {
devDependencies: [
'**/*.test.js',
'**/*.test.jsx',
'**/*.test.ts',
'**/*.test.tsx',
],
}],
'import/extensions': ['error', 'ignorePackages', {
js: 'never',
jsx: 'never',
ts: 'never',
tsx: 'never',
}],
'react/jsx-filename-extension': [2, {
extensions: ['.js', '.jsx', '.ts', '.tsx'],
}],
'jsx-a11y/label-has-associated-control': ['error', { assert: 'either' }],
},
};
.vscode/settings.json
{
"editor.rulers": [
80
],
"editor.codeActionsOnSave": {
"source.fixAll.eslint": true
},
// "trailing-spaces.trimOnSave": true
}
'웹 개발 > React' 카테고리의 다른 글
Tanstack react-query (0) | 2023.07.05 |
---|---|
React ) vite + ts + eslint (0) | 2023.07.05 |
전 후 값으로 변경하는 버튼 (배열 안에서 전 후 값으로 이동하기) (0) | 2023.05.31 |
[React Router v6] createBrowserRouter 레이아웃 여러개 (0) | 2023.04.06 |
[error] @parcel/transformer-js: Browser scripts cannot have imports or exports. (0) | 2023.03.02 |