Skip to content

Commit

Permalink
feat: enable pre-pr lint (#15)
Browse files Browse the repository at this point in the history
  • Loading branch information
melikhov-dev authored Aug 10, 2023
1 parent 6a0f632 commit f99fdee
Show file tree
Hide file tree
Showing 11 changed files with 212 additions and 158 deletions.
7 changes: 7 additions & 0 deletions .eslintrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{
"extends": ["./index.js", "./prettier.js"],
"root": true,
"env": {
"node": true
}
}
26 changes: 26 additions & 0 deletions .github/workflows/ci.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
name: CI

on:
push:
branches: [main]
pull_request:
branches: [main]

jobs:
verify_files:
name: Verify Files
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v2
with:
fetch-depth: 0
- name: Setup Node
uses: actions/setup-node@v2
with:
node-version: '18.x'
cache: 'npm'
- name: Install Packages
run: npm ci
- name: Lint Files
run: npm run lint
1 change: 1 addition & 0 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,3 +12,4 @@ jobs:
with:
github-token: ${{ secrets.GRAVITY_UI_BOT_GITHUB_TOKEN }}
npm-token: ${{ secrets.GRAVITY_UI_BOT_NPM_TOKEN }}
node-version: 18
1 change: 1 addition & 0 deletions .prettierrc.js
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
module.exports = require('@gravity-ui/prettier-config');
2 changes: 1 addition & 1 deletion a11y.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ module.exports = {
extends: ['plugin:jsx-a11y/recommended'],
parserOptions: {
ecmaFeatures: {
jsx: true
jsx: true,
},
},
};
219 changes: 116 additions & 103 deletions base.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,11 +20,11 @@ module.exports = {
// Best Practices
'array-callback-return': ERROR,
'block-scoped-var': WARNING,
'complexity': WARNING,
complexity: WARNING,
'consistent-return': WARNING,
'curly': ERROR,
curly: ERROR,
'dot-location': [ERROR, 'property'],
'eqeqeq': [WARNING, 'always'],
eqeqeq: [WARNING, 'always'],
'guard-for-in': ERROR,
'no-caller': ERROR,
'no-console': WARNING,
Expand Down Expand Up @@ -59,7 +59,7 @@ module.exports = {
'no-useless-concat': ERROR,
'no-void': ERROR,
'no-with': ERROR,
'radix': WARNING,
radix: WARNING,
'wrap-iife': [ERROR, 'inside'],

// Variables
Expand All @@ -76,7 +76,7 @@ module.exports = {
'no-path-concat': WARNING,

// Stylistic Issues
'camelcase': [ERROR, {properties: 'never'}],
camelcase: [ERROR, {properties: 'never'}],
'comma-style': [ERROR, 'last'],
'max-depth': [WARNING, {maximum: 5}],
'new-cap': ERROR,
Expand All @@ -89,9 +89,12 @@ module.exports = {
'no-new-object': WARNING,
'no-restricted-syntax': [ERROR, 'WithStatement'],
'no-unneeded-ternary': ERROR,
'sort-imports': [ERROR, {
ignoreDeclarationSort: true
}],
'sort-imports': [
ERROR,
{
ignoreDeclarationSort: true,
},
],

// ECMAStrict 6
'no-duplicate-imports': ERROR,
Expand All @@ -108,112 +111,122 @@ module.exports = {
'import/order': [
ERROR,
{
'alphabetize': {
order: 'asc'
alphabetize: {
order: 'asc',
},
'newlines-between': 'always',
'groups': [
'builtin',
'external',
'internal',
'parent',
'sibling',
'index'
],
'warnOnUnassignedImports': true
}
]
groups: ['builtin', 'external', 'internal', 'parent', 'sibling', 'index'],
warnOnUnassignedImports: true,
},
],
},
overrides: [{
files: ['*.ts', '*.tsx'],
parser: '@typescript-eslint/parser',
plugins: ['@typescript-eslint'],
rules: {
// TypeScript compiler handles these on its own
'strict': OFF,
'no-undef': OFF,
'no-dupe-class-members': OFF,
overrides: [
{
files: ['*.ts', '*.tsx'],
parser: '@typescript-eslint/parser',
plugins: ['@typescript-eslint'],
rules: {
// TypeScript compiler handles these on its own
strict: OFF,
'no-undef': OFF,
'no-dupe-class-members': OFF,

'valid-jsdoc': [WARNING, {
// type annotations are redundant when in TS files
requireReturnType: false,
requireParamType: false,
// same as for JS
requireParamDescription: false,
requireReturnDescription: false,
}],
'valid-jsdoc': [
WARNING,
{
// type annotations are redundant when in TS files
requireReturnType: false,
requireParamType: false,
// same as for JS
requireParamDescription: false,
requireReturnDescription: false,
},
],

// TypeScript-specific extension rules
'no-array-constructor': OFF,
'no-duplicate-imports': OFF,
'no-loop-func': OFF,
'no-redeclare': OFF,
'no-shadow': OFF,
'no-unused-expressions': OFF,
'no-unused-vars': OFF,
'no-use-before-define': OFF,
'no-useless-constructor': OFF,
'@typescript-eslint/no-array-constructor': WARNING,
'@typescript-eslint/no-duplicate-imports': ERROR,
'@typescript-eslint/no-loop-func': ERROR,
'@typescript-eslint/no-redeclare': ERROR,
'@typescript-eslint/no-shadow': WARNING,
'@typescript-eslint/no-unused-expressions': ERROR,
'@typescript-eslint/no-unused-vars': [ERROR, {
argsIgnorePattern: '^_',
varsIgnorePattern: '^_',
}],
'@typescript-eslint/no-use-before-define': [WARNING, {functions: false}],
'@typescript-eslint/no-useless-constructor': ERROR,
// TypeScript-specific extension rules
'no-array-constructor': OFF,
'no-duplicate-imports': OFF,
'no-loop-func': OFF,
'no-redeclare': OFF,
'no-shadow': OFF,
'no-unused-expressions': OFF,
'no-unused-vars': OFF,
'no-use-before-define': OFF,
'no-useless-constructor': OFF,
'@typescript-eslint/no-array-constructor': WARNING,
'@typescript-eslint/no-duplicate-imports': ERROR,
'@typescript-eslint/no-loop-func': ERROR,
'@typescript-eslint/no-redeclare': ERROR,
'@typescript-eslint/no-shadow': WARNING,
'@typescript-eslint/no-unused-expressions': ERROR,
'@typescript-eslint/no-unused-vars': [
ERROR,
{
argsIgnorePattern: '^_',
varsIgnorePattern: '^_',
},
],
'@typescript-eslint/no-use-before-define': [WARNING, {functions: false}],
'@typescript-eslint/no-useless-constructor': ERROR,

'@typescript-eslint/naming-convention': [
ERROR,
{
selector: 'typeLike',
format: ['PascalCase'],
leadingUnderscore: 'forbid',
},
],
'@typescript-eslint/member-delimiter-style': ERROR,
'@typescript-eslint/member-ordering': [ERROR, {
'default': [
'public-static-field',
'protected-static-field',
'private-static-field',
'@typescript-eslint/naming-convention': [
ERROR,
{
selector: 'typeLike',
format: ['PascalCase'],
leadingUnderscore: 'forbid',
},
],
'@typescript-eslint/member-delimiter-style': ERROR,
'@typescript-eslint/member-ordering': [
ERROR,
{
default: [
'public-static-field',
'protected-static-field',
'private-static-field',

'public-static-method',
'protected-static-method',
'private-static-method',
'public-static-method',
'protected-static-method',
'private-static-method',

'public-instance-field',
'protected-instance-field',
'private-instance-field',
'public-instance-field',
'protected-instance-field',
'private-instance-field',

'constructor',
'constructor',

'public-instance-method',
'protected-instance-method',
'private-instance-method',
'public-instance-method',
'protected-instance-method',
'private-instance-method',
],
},
],
}],
'@typescript-eslint/explicit-member-accessibility': [ERROR, {'accessibility': 'no-public'}],
'@typescript-eslint/consistent-type-assertions': ERROR,
'@typescript-eslint/no-explicit-any': WARNING,
'@typescript-eslint/no-inferrable-types': ERROR,
'@typescript-eslint/no-namespace': ERROR,
'@typescript-eslint/no-non-null-assertion': WARNING,
'@typescript-eslint/no-parameter-properties': ERROR,
'@typescript-eslint/triple-slash-reference': ERROR,
'@typescript-eslint/prefer-namespace-keyword': ERROR,
'@typescript-eslint/type-annotation-spacing': [ERROR, {
before: true,
after: true,
overrides: {
colon: {
before: false,
'@typescript-eslint/explicit-member-accessibility': [
ERROR,
{accessibility: 'no-public'},
],
'@typescript-eslint/consistent-type-assertions': ERROR,
'@typescript-eslint/no-explicit-any': WARNING,
'@typescript-eslint/no-inferrable-types': ERROR,
'@typescript-eslint/no-namespace': ERROR,
'@typescript-eslint/no-non-null-assertion': WARNING,
'@typescript-eslint/no-parameter-properties': ERROR,
'@typescript-eslint/triple-slash-reference': ERROR,
'@typescript-eslint/prefer-namespace-keyword': ERROR,
'@typescript-eslint/type-annotation-spacing': [
ERROR,
{
before: true,
after: true,
overrides: {
colon: {
before: false,
},
},
},
},
}],
],
},
},
}],
],
};
2 changes: 1 addition & 1 deletion constants.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
module.exports = {
OFF: 0,
WARNING: 1,
ERROR: 2
ERROR: 2,
};
20 changes: 15 additions & 5 deletions package-lock.json

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

4 changes: 3 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,8 @@
"homepage": "https://github.com/gravity-ui/eslint-config#readme",
"scripts": {
"prepare": "husky install",
"test": "echo \"Error: no test specified\" && exit 0"
"test": "echo \"Error: no test specified\" && exit 0",
"lint": "eslint ."
},
"dependencies": {
"@babel/core": "7.16.0",
Expand All @@ -46,6 +47,7 @@
"devDependencies": {
"@commitlint/cli": "17.0.3",
"@commitlint/config-conventional": "17.0.3",
"@gravity-ui/prettier-config": "^1.0.1",
"eslint": "8.8.0",
"husky": "8.0.1"
},
Expand Down
Loading

0 comments on commit f99fdee

Please sign in to comment.