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

fix(react): apply react rules only in tsx and jsx #49

Open
wants to merge 6 commits into
base: develop
Choose a base branch
from
Open
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
10 changes: 5 additions & 5 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ jobs:
- uses: EndBug/add-and-commit@v9
with:
default_author: github_actions
message: 'chore(deps): bump @singularit/eslint-config-basic'
message: 'feat(deps): bump @singularit/eslint-config-basic'
- name: 🚀 Release @singularit/eslint-config-typescript
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
Expand All @@ -41,7 +41,7 @@ jobs:
- uses: EndBug/add-and-commit@v9
with:
default_author: github_actions
message: 'chore(deps): bump @singularit/eslint-config-typescript'
message: 'feat(deps): bump @singularit/eslint-config-typescript'
- name: 🚀 Release @singularit/eslint-config-vue
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
Expand All @@ -54,7 +54,7 @@ jobs:
- uses: EndBug/add-and-commit@v9
with:
default_author: github_actions
message: 'chore(deps): bump @singularit/eslint-config-vue'
message: 'feat(deps): bump @singularit/eslint-config-vue'
- name: 🚀 Release @singularit/eslint-config-react
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
Expand All @@ -67,7 +67,7 @@ jobs:
- uses: EndBug/add-and-commit@v9
with:
default_author: github_actions
message: 'chore(deps): bump @singularit/eslint-config-react'
message: 'feat(deps): bump @singularit/eslint-config-react'
- name: 🚀 Release @singularit/eslint-config
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
Expand All @@ -80,4 +80,4 @@ jobs:
- uses: EndBug/add-and-commit@v9
with:
default_author: github_actions
message: 'chore(deps): bump @singularit/eslint-config'
message: 'feat(deps): bump @singularit/eslint-config'
3 changes: 2 additions & 1 deletion configs/all/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,8 @@
"singularIT",
"vue",
"typescript",
"react"
"react",
"javascript"
],
"main": "index.js",
"files": [
Expand Down
6 changes: 3 additions & 3 deletions configs/basic/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -256,9 +256,9 @@ module.exports = {
balanced: true,
},
}],
//consistency
'array-element-newline':["error", "consistent"],
'object-property-newline': ['error','allowMultiplePropertiesPerLine'],
// consistency
'array-element-newline': ['error', 'consistent'],
'object-property-newline': ['error', {allowMultiplePropertiesPerLine: true}],

// best-practice
'array-callback-return': 'error',
Expand Down
181 changes: 94 additions & 87 deletions configs/react/index.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,8 @@
module.exports = {
const { isPackageExists } = require('local-pkg')

const react = isPackageExists('react')

module.exports = react ? {
plugins: [
'react',
'react-hooks',
Expand All @@ -8,7 +12,7 @@ module.exports = {
'plugin:react/recommended',
'plugin:react-hooks/recommended',
'plugin:react/jsx-runtime',
'@singularit',
'@singularit/eslint-config-typescript',
],
settings: {
react: {
Expand All @@ -30,90 +34,93 @@ module.exports = {
}],
},
},
],
rules: {
// general react rules
'react-prefer-function-component/react-prefer-function-component': 'error', // Forbid use of class components
'react/no-array-index-key': 'warn', // Using index as key can lead to unnecessary rerenders
'react/no-danger': 'error', // Prevent usage of dangerouslySetInnerHTML
'react/no-invalid-html-attribute': 'error', // Forbid attribute with invalid value
'react/no-multi-comp': 'warn', // Enforce proper code splitting
'react/no-namespace': 'error', // Prevent usage of the namespaces
'react/no-unstable-nested-components': 'error', // Prevent usage of unstable nested components
'react/no-unused-prop-types': 'error', // Prevent unused prop types
'react/forbid-component-props': 'warn', // No custom component should use html attributes
'react/self-closing-comp': 'error', // Prevent extra closing tags for components without children
'react/void-dom-elements-no-children': 'error', // Prevent passing of children to void DOM elements
// FC specific rules
'react-hooks/exhaustive-deps': 'warn', // Validate the list of dependencies used by hooks
'react-hooks/rules-of-hooks': 'error', // Enforces rules of Hooks (see https://reactjs.org/docs/hooks-rules.html)
'react/hook-use-state': 'error', // Ensure symmetric naming of useState hook value and setter
'react/function-component-definition': [ // Enforce arrow function components
'error',
{
namedComponents: ['arrow-function'],
unnamedComponents: ['arrow-function'],
},
],
// CC specific rules
'react/no-access-state-in-setstate': 'warn', // Prevent access to this.state in setState
'react/no-arrow-function-lifecycle': 'error', // Prevent arrow functions in component lifecycle methods
'react/no-did-mount-set-state': 'error', // Prevent usage of setState in componentDidMount
'react/no-did-update-set-state': 'error', // Prevent usage of setState in componentDidUpdate
'react/no-will-update-set-state': 'error', // Prevent usage of setState in componentWillUpdate
'react/no-redundant-should-component-update': 'error', // Prevent usage of shouldComponentUpdate when extending React.PureComponent
'react/no-unsafe': 'error', // Prevent usage of unsafe lifecycle methods
'react/no-unused-class-component-methods': 'error', // Prevent unused methods in CC
'react/no-unused-state': 'error', // Prevent unused state variables
'react/prefer-es6-class': ['error', 'always'], // Prefer ES6 class over React.createClass
'react/sort-comp': 'error', // Enforce sorted methods in class components
// JSX specific rules
'jsx-quotes': ['error', 'prefer-double'],
'react/jsx-boolean-value': 'error', // Enforce boolean attributes notation in JSX
'react/jsx-closing-bracket-location': 'error', // Validate closing bracket location in JSX
'react/jsx-closing-tag-location': 'error', // Validate closing tag location for multiline JSX
'react/jsx-first-prop-new-line': ['error', 'multiline'], // Ensure proper position of the first property in JSX
'react/jsx-fragments': 'error', // Enforce fragment shorthand syntax
'react/jsx-indent': ['error', 2], // Enforce consistent 2-space indentation in JSX
'react/jsx-indent-props': ['error', 2], // Enforce consistent 2-space indentation for props in JSX
'react/jsx-max-props-per-line': [ // Enforce a maximum of three props per line in JSX
'error',
{
maximum: 3,
},
],
'react/jsx-no-constructed-context-values': 'error', // Prevents JSX context provider values from taking values that will cause needless rerenders
'react/jsx-no-leaked-render': [ // Prevent problematic leaked values from being rendered
'error',
{
validStrategies: [
'coerce',
'ternary',
{
files: ['*.tsx', '*.jsx'],
rules: {
// general react rules
'react-prefer-function-component/react-prefer-function-component': 'error', // Forbid use of class components
'react/no-array-index-key': 'warn', // Using index as key can lead to unnecessary rerenders
'react/no-danger': 'error', // Prevent usage of dangerouslySetInnerHTML
'react/no-invalid-html-attribute': 'error', // Forbid attribute with invalid value
'react/no-multi-comp': 'warn', // Enforce proper code splitting
'react/no-namespace': 'error', // Prevent usage of the namespaces
'react/no-unstable-nested-components': 'error', // Prevent usage of unstable nested components
'react/no-unused-prop-types': 'error', // Prevent unused prop types
'react/forbid-component-props': 'warn', // No custom component should use html attributes
'react/self-closing-comp': 'error', // Prevent extra closing tags for components without children
'react/void-dom-elements-no-children': 'error', // Prevent passing of children to void DOM elements
// FC specific rules
'react-hooks/exhaustive-deps': 'warn', // Validate the list of dependencies used by hooks
'react-hooks/rules-of-hooks': 'error', // Enforces rules of Hooks (see https://reactjs.org/docs/hooks-rules.html)
'react/hook-use-state': 'error', // Ensure symmetric naming of useState hook value and setter
'react/function-component-definition': [ // Enforce arrow function components
'error',
{
namedComponents: ['arrow-function'],
unnamedComponents: ['arrow-function'],
},
],
},
],
'react/jsx-no-useless-fragment': 'error', // Prevent unnecessary JSX fragments
'react/jsx-pascal-case': 'error', // Enforce PascalCase for custom JSX components
'react/jsx-props-no-multi-spaces': 'error', // Prevent multiple spaces between JSX props
'react/jsx-tag-spacing': [ // Enforce consistent spacing between tags and their attributes
'error',
{
beforeClosing: 'never',
beforeSelfClosing: 'always',
},
],
'react/jsx-wrap-multilines': [ // Enforce consistent wrap of multiline JSX
'error',
{
declaration: 'parens-new-line',
assignment: 'parens-new-line',
return: 'parens-new-line',
arrow: 'parens-new-line',
condition: 'parens-new-line',
logical: 'parens-new-line',
prop: 'parens-new-line',
},
],
},
}
// CC specific rules
'react/no-access-state-in-setstate': 'warn', // Prevent access to this.state in setState
'react/no-arrow-function-lifecycle': 'error', // Prevent arrow functions in component lifecycle methods
'react/no-did-mount-set-state': 'error', // Prevent usage of setState in componentDidMount
'react/no-did-update-set-state': 'error', // Prevent usage of setState in componentDidUpdate
'react/no-will-update-set-state': 'error', // Prevent usage of setState in componentWillUpdate
'react/no-redundant-should-component-update': 'error', // Prevent usage of shouldComponentUpdate when extending React.PureComponent
'react/no-unsafe': 'error', // Prevent usage of unsafe lifecycle methods
'react/no-unused-class-component-methods': 'error', // Prevent unused methods in CC
'react/no-unused-state': 'error', // Prevent unused state variables
'react/prefer-es6-class': ['error', 'always'], // Prefer ES6 class over React.createClass
'react/sort-comp': 'error', // Enforce sorted methods in class components
// JSX specific rules
'jsx-quotes': ['error', 'prefer-double'],
'react/jsx-boolean-value': 'error', // Enforce boolean attributes notation in JSX
'react/jsx-closing-bracket-location': 'error', // Validate closing bracket location in JSX
'react/jsx-closing-tag-location': 'error', // Validate closing tag location for multiline JSX
'react/jsx-first-prop-new-line': ['error', 'multiline'], // Ensure proper position of the first property in JSX
'react/jsx-fragments': 'error', // Enforce fragment shorthand syntax
'react/jsx-indent': ['error', 2], // Enforce consistent 2-space indentation in JSX
'react/jsx-indent-props': ['error', 2], // Enforce consistent 2-space indentation for props in JSX
'react/jsx-max-props-per-line': [ // Enforce a maximum of three props per line in JSX
'error',
{
maximum: 3,
},
],
'react/jsx-no-constructed-context-values': 'error', // Prevents JSX context provider values from taking values that will cause needless rerenders
'react/jsx-no-leaked-render': [ // Prevent problematic leaked values from being rendered
'error',
{
validStrategies: [
'coerce',
'ternary',
],
},
],
'react/jsx-no-useless-fragment': 'error', // Prevent unnecessary JSX fragments
'react/jsx-pascal-case': 'error', // Enforce PascalCase for custom JSX components
'react/jsx-props-no-multi-spaces': 'error', // Prevent multiple spaces between JSX props
'react/jsx-tag-spacing': [ // Enforce consistent spacing between tags and their attributes
'error',
{
beforeClosing: 'never',
beforeSelfClosing: 'always',
},
],
'react/jsx-wrap-multilines': [ // Enforce consistent wrap of multiline JSX
'error',
{
declaration: 'parens-new-line',
assignment: 'parens-new-line',
return: 'parens-new-line',
arrow: 'parens-new-line',
condition: 'parens-new-line',
logical: 'parens-new-line',
prop: 'parens-new-line',
},
],
}
}
],
} : {}

3 changes: 2 additions & 1 deletion configs/react/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,8 @@
"@singularit/eslint-config-typescript": "^1.1.3",
"eslint-plugin-react": "^7.30.1",
"eslint-plugin-react-hooks": "^4.6.0",
"eslint-plugin-react-prefer-function-component": "^3.0.0"
"eslint-plugin-react-prefer-function-component": "^3.0.0",
"local-pkg": "^0.4.2"
},
"devDependencies": {
"eslint": "^8.16.0"
Expand Down
7 changes: 5 additions & 2 deletions configs/vue/index.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
module.exports = {
const {isPackageExists} = require("local-pkg");
const vue = isPackageExists('vue')

module.exports = vue ? {
overrides: [
{
files: ['*.vue'],
Expand All @@ -13,4 +16,4 @@ module.exports = {
'@singularit/eslint-config-typescript',
],
rules: {},
}
} : {}
3 changes: 2 additions & 1 deletion configs/vue/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,8 @@
},
"dependencies": {
"@singularit/eslint-config-typescript": "^1.1.3",
"eslint-plugin-vue": "^9.0.1"
"eslint-plugin-vue": "^9.0.1",
"local-pkg": "^0.4.2"
},
"devDependencies": {
"eslint": "^8.16.0"
Expand Down
23 changes: 21 additions & 2 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.