/
austin_s
/
react-interview-components
Обзор
Документация
Войти
/
austin_s
/
react-interview-components
Код
Пакеты
0
Релизы
0
Аналитика
Безопасность
master
docs/Linters.mdx
107 строк
5 KB
spanic
adds TypeScript: start - ✅, build:lib - ✅, storybook - ❌
04 сен 2023, 21:25
04 сен 2023, 21:25
c21b3d3
Код
Авторство
О чём код?
import {Meta} from '@storybook/blocks'; <Meta title="Docs/Linters" /> # Code quality tools Since you are creating library to share with the community, code quality matters a lot. Template provides eslint and stylelint configurations to improve and maintain your code. Code linting is performed inside IDE and when you commit your code. Thus every time you commit something [husky](https://github.com/typicode/husky) will run [lint-staged](https://github.com/okonet/lint-staged) with `eslint --fix` command on staged files, preventing you from committing badly formatted code. You can change or disable this behavior inside `.linstagedrc` config file. Before each push tests will run in the same manner. ### Caveats - If pre-commit hooks not work (e. g. your code is not linted after commit), run `yarn add husky` in your project folder. ## eslint ```shell script yarn lint:js # runs eslint in src directory yarn fix:js # runs eslint in src directory with --fix parameter ``` Template extends [CRA eslint rules](https://github.com/facebook/create-react-app/tree/master/packages/eslint-config-react-app) with custom set, tailored for reasonable and clean development process. I added `prettier` to force consistent formatting and `eslint-plugin-fp` to avoid accidental mutations. Don't like trailing semicolons? Feel free to [tweak prettier rules](https://prettier.io/docs/en/configuration.html) inside `.prettierrc` file to match your code style. Eslint rules are commented for your convenience, feel free to tweak or remove them. No judgement. ```js // Allow jsx tags inside .js and TypeScript files. "react/jsx-filename-extension": [1, {"extensions": [".js", ".jsx", '.tsx']}], // Disable props spreading (<App {...props} />) warning. "react/jsx-props-no-spreading": 0, // Throw warning instead of error when using array index as a key. "react/no-array-index-key": 1, // Allow modules with named exports only. "import/prefer-default-export": 0, // Force {foo: 'bar'} object literal syntax. "object-curly-spacing": ["error", "never"], // Throw warning instead of error when function is not properly formatted. // Feel free to choose your favorite option https://eslint.org/docs/rules/arrow-body-style "arrow-body-style": ["warn", "as-needed"], // Make prettier code formatting suggestions more verbose. "prettier/prettier": ["warn"], // Throw warning when <a href="#"> or <a href="javascript:void(0)"> are used. // Use <button> instead. "jsx-a11y/anchor-is-valid": ["warn", {"aspects": ["invalidHref"]}], // Allow using (props) => <Component /> and ({propName}) => <Component /> syntax. "react/destructuring-assignment": "off", // Disable <Fragment> => <> replacement. Feel free to change "react/jsx-fragments": "off", // Below is the set of functional rules to warn developer about accidental mutations, // which may cause error in reducers etc. // No delete operator. "fp/no-delete": "warn", // Warning when Object.assign(a, b) used, since it mutates first argument. // Object.assign({}, a, b) is ok. "fp/no-mutating-assign": "warn", // Warning when mutating method (pop, push, reverse, shift, sort, splice, unshift, etc) // is used. Ramda and lodash/fp are allowed (_.pop, R.push) "fp/no-mutating-methods": [ "warn", { "allowedObjects": ["_", "R"] } ], // Warning when mutating operators (++, --, etc) are used, object = {} also. // `Component.propTypes`, `Component.defaultProps`, common.js (`module.exports`) // and `ref.current` are ok. "fp/no-mutation": [ "warn", { "commonjs": true, "allowThis": true, "exceptions": [{"property": "propTypes"}, {"property": "defaultProps"}, {"property": "current"}] } ] ``` ## stylelint ```shell script yarn lint:style # runs stylelint in src directory yarn fix:style # runs stylelint in src directory with --fix parameter ``` Template includes [stylelint](https://stylelint.io/), to check CSS/SASS/LESS files. We are using [`stylelint-config-standard`](https://github.com/stylelint/stylelint-config-standard) rule set extended with: ```js // Check `calc` functions formatting, required for `calc` to work in IE11 "function-calc-no-unspaced-operator": true, // Custom rules (aka CSS vars) should go first "order/order": [ "custom-properties", "declarations" ], // Require rules to be in alphabetical order "order/properties-alphabetical-order": true, // Disallow vendor prefixes, since CRA has autoprefixer enabled "property-no-vendor-prefix": true, "media-feature-name-no-vendor-prefix": true, "at-rule-no-vendor-prefix": true, "selector-no-vendor-prefix": true, // Limit rules nesting for readablity purposes "max-nesting-depth": 3, // Limit selector complexity for readablity purposes "selector-max-compound-selectors": 5 ``` Stylelint errors don't prevent build of application in development mode.