Skip to content

Commit

Permalink
ci(lint): Move eslint config to root. Add GH workflow to run lint. (#…
Browse files Browse the repository at this point in the history
…1109)

- auto-fix minor lint warnings.
  • Loading branch information
jafin authored Jul 26, 2023
1 parent 6b5ba95 commit 762ca42
Show file tree
Hide file tree
Showing 39 changed files with 475 additions and 6,359 deletions.
13 changes: 13 additions & 0 deletions .eslintignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
**/*.d.ts
packages/**/dist/**/*
packages/**/public/**/*
packages/**/coverage/**/*
packages/**/fixtures/**/*
node_modules
# TODO Disable examples, we want to include it.
examples/**/*
public/**/*
scripts/**/*
.github
.changeset
vite.config.js
170 changes: 154 additions & 16 deletions .eslintrc.cjs
Original file line number Diff line number Diff line change
@@ -1,18 +1,156 @@
module.exports = {
extends: [__dirname+'/config/defaultEslintConfig.cjs'],
parserOptions: {
project: './tsconfig.eslint.json',
tsconfigRootDir: __dirname,
parser: '@typescript-eslint/parser',
root: true,
extends: [
// 'standard',
'plugin:react/recommended',
'plugin:react-hooks/recommended',
'eslint:recommended',
'plugin:@typescript-eslint/eslint-recommended',
'plugin:@typescript-eslint/recommended',
//'plugin:@typescript-eslint/recommended-type-checked', //ideally we want this on
// 'plugin:@typescript-eslint/stylistic-type-checked',
'plugin:import/typescript',
'plugin:jsx-a11y/recommended',
'prettier', // must be last
],
plugins: ['@typescript-eslint', 'simple-import-sort', 'testing-library', 'react', 'prettier'],
parserOptions: {
project: ['./tsconfig.eslint.json', './packages/*/tsconfig.eslint.json'],
ecmaVersion: 2022,
sourceType: 'module',
ecmaFeatures: {
jsx: true,
},
rules: {
'@typescript-eslint/naming-convention': [
'error',
{
'selector': 'variable',
'types': ['boolean'],
'format': ['PascalCase'],
'prefix': ['is', 'with', 'should', 'has', 'can', 'did', 'will']
}
]
}
}
warnOnUnsupportedTypeScriptVersion: true,
},
rules: {
// '@typescript-eslint/naming-convention': [
// 'error',
// {
// selector: 'variable',
// types: ['boolean'],
// format: ['PascalCase'],
// prefix: ['is', 'with', 'should', 'has', 'can', 'did', 'will'],
// },
// ],
'@typescript-eslint/interface-name-prefix': 'off',
'@typescript-eslint/no-non-null-assertion': 'off',
'@typescript-eslint/explicit-module-boundary-types': 'off',
'@typescript-eslint/no-explicit-any': 'off',
'@typescript-eslint/ban-ts-comment': 'off',
'no-unused-vars': 'off',
'@typescript-eslint/no-unused-vars': [
'error',
{
argsIgnorePattern: '^_|req|res|next|err|ctx|args|context|info|index|data',
ignoreRestSiblings: true,
},
],
'no-array-constructor': 'off',
'@typescript-eslint/no-array-constructor': 'warn',
'no-redeclare': 'off',
'@typescript-eslint/no-redeclare': 'warn',
'no-use-before-define': 'off',
'@typescript-eslint/no-use-before-define': [
'warn',
{
functions: false,
classes: false,
variables: false,
typedefs: false,
},
],
'no-unused-expressions': 'off',
'@typescript-eslint/no-unused-expressions': [
'error',
{
allowShortCircuit: true,
allowTernary: true,
allowTaggedTemplates: true,
},
],
'@typescript-eslint/triple-slash-reference': 'off',
'@typescript-eslint/member-delimiter-style': [
'error',
{
multiline: {
delimiter: 'semi',
requireLast: true,
},
singleline: {
delimiter: 'semi',
requireLast: false,
},
},
],
camelcase: 'off',
'comma-dangle': [
'error',
{
arrays: 'always-multiline',
objects: 'always-multiline',
imports: 'always-multiline',
exports: 'always-multiline',
functions: 'always-multiline',
},
],
'array-callback-return': 'warn',
'jsx-quotes': ['error', 'prefer-double'],
// 'max-len': ['error', { code: 120 }],
indent: 'off',
// quotes: ['error', 'single'],
semi: ['error', 'always'],
'space-before-function-paren': 'off',

'import/no-named-as-default': 'off',
'import/no-named-as-default-member': 'off',
'import/default': 'off',
'import/named': 'off',
'import/namespace': 'off',
'import/no-unresolved': 'off',
'simple-import-sort/imports': 'error',
'simple-import-sort/exports': 'error',
'react/prop-types': 'off',
'react/jsx-wrap-multilines': 'error',
'react/react-in-jsx-scope': 'off',
'react/display-name': 'off',
// https://github.com/facebook/react/tree/master/packages/-react-hooks
'react-hooks/rules-of-hooks': 'error',
'react-hooks/exhaustive-deps': 'off',
},

overrides: [
{
files: ['*.js', '*.jsx'],
rules: {
'@typescript-eslint/no-var-requires': 'off',
},
},
{
// 3) Now we enable -testing-library rules or preset only for matching files!
files: ['**/?(*.)+(spec|test).[jt]s?(x)'],
extends: ['plugin:testing-library/react'],
rules: {
'testing-library/await-async-query': 'error',
'testing-library/no-await-sync-query': 'error',
'testing-library/no-debugging-utils': 'warn',
'testing-library/no-dom-import': 'off',
'testing-library/no-unnecessary-act': 'off',
},
},
],
settings: {
react: {
version: 'detect',
},
// 'import/parsers': {
// '@typescript-eslint/parser': ['.ts', '.tsx'],
// },
'import/resolver': {
typescript: {
alwaysTryTypes: true,
},
},
},
};
45 changes: 45 additions & 0 deletions .github/workflows/lint.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
name: Lint

on:
# Trigger the workflow on push or pull request,
# but only for the main branch
push:
# branches:
# - main
pull_request:
# branches:
# - main

env:
PNPM_VERSION: 8.5.1
NODE_VERSION: 18

jobs:
run-linters:
name: Run linters
runs-on: ubuntu-latest

steps:
- name: Check out Git repository
uses: actions/checkout@v3

- name: Install node.js
uses: actions/setup-node@v3
with:
node-version: ${{ env.NODE_VERSION }}

- uses: pnpm/action-setup@v2
name: Install pnpm
with:
version: ${{ env.PNPM_VERSION }}
run_install: false

# ESLint and Prettier must be in `package.json`
- name: Install dependencies
run: pnpm i

- name: Run linters
uses: wearerequired/lint-action@v2
with:
eslint: true
prettier: false #runs part of eslint
11 changes: 11 additions & 0 deletions .prettierignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
# deep dirs
**/dist
**/node_modules
**/fixtures

# directories
.github
.changeset

# files
pnpm-lock.yaml
18 changes: 18 additions & 0 deletions .prettierrc.cjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
module.exports = {
printWidth: 100,
semi: true,
singleQuote: true,
jsxSingleQuote: true,
tabWidth: 2,
trailingComma: 'es5',
useTabs: true,
plugins: [],
overrides: [
{
files: ['.*', '*.json', '*.md', '*.toml', '*.yml'],
options: {
useTabs: false,
},
},
],
};
4 changes: 0 additions & 4 deletions .prettierrc.json

This file was deleted.

1 change: 0 additions & 1 deletion __mocks__/fileMock.js

This file was deleted.

1 change: 0 additions & 1 deletion __mocks__/styleMock.js

This file was deleted.

Loading

0 comments on commit 762ca42

Please sign in to comment.