[git actions] Add GitHub Actions job for lint and format checks

This commit is contained in:
Sergey Konovalov
2025-08-06 18:55:44 +03:00
parent 2a222d9a9b
commit c0b7849a0f
3 changed files with 81 additions and 18 deletions

63
.github/workflows/lint-format.yml vendored Normal file
View File

@ -0,0 +1,63 @@
name: Lint & Format
on:
push:
branches:
- 'main'
- 'master'
- 'develop'
- 'hotfix/**'
- 'release/**'
pull_request:
branches:
- 'main'
- 'master'
- 'develop'
- 'hotfix/**'
- 'release/**'
types: [opened, synchronize, reopened]
jobs:
code-quality:
name: Code Quality Check
runs-on: ubuntu-latest
timeout-minutes: 15
permissions:
contents: read
pull-requests: write
strategy:
fail-fast: false
matrix:
node-version: [18.x, 20.x]
steps:
- name: Checkout repository
uses: actions/checkout@v4
- name: Setup Node.js ${{ matrix.node-version }}
uses: actions/setup-node@v4
with:
node-version: ${{ matrix.node-version }}
cache: 'npm'
- name: Install dependencies
run: npm ci
- name: Run ESLint
run: npm run lint
- name: Check Prettier formatting
run: npm run format:check
- name: Comment PR (on failure)
if: failure() && github.event_name == 'pull_request'
uses: actions/github-script@v7
with:
script: |
github.rest.issues.createComment({
issue_number: context.issue.number,
owner: context.repo.owner,
repo: context.repo.repo,
body: '❌ **Code Quality Check Failed**\n\nPlease run `npm run code:fix` to fix linting and formatting issues, then commit the changes.'
})

View File

@ -1,5 +1,5 @@
{
"printWidth": 120,
"printWidth": 150,
"tabWidth": 2,
"useTabs": false,
"semi": true,

View File

@ -1,7 +1,7 @@
const js = require('@eslint/js');
const globals = require('globals');
const prettier = require('eslint-config-prettier');
const { includeIgnoreFile } = require('@eslint/compat');
const {includeIgnoreFile} = require('@eslint/compat');
const path = require('node:path');
const gitignorePath = path.resolve(__dirname, '.gitignore');
@ -15,8 +15,8 @@ module.exports = [
ecmaVersion: 2022,
sourceType: 'module',
globals: {
...globals.node, // All Node.js globals automatically
...globals.es2022 // Modern JavaScript globals
...globals.node, // All Node.js globals automatically
...globals.es2022 // Modern JavaScript globals
}
},
rules: {
@ -30,22 +30,22 @@ module.exports = [
}
],
'no-undef': 'error',
'eqeqeq': ['error', 'smart'],
'curly': ['error', 'all'],
eqeqeq: ['error', 'smart'],
curly: ['error', 'all'],
// Server-friendly settings
'no-console': 'off', // Allow console in server code
'no-continue': 'off', // Allow continue statements
'no-plusplus': ['error', { allowForLoopAfterthoughts: true }],
'no-console': 'off', // Allow console in server code
'no-continue': 'off', // Allow continue statements
'no-plusplus': ['error', {allowForLoopAfterthoughts: true}],
// Modern JavaScript practices
'prefer-const': 'error', // Enforce const for immutable bindings
'no-var': 'error', // Enforce let/const over var
'object-shorthand': 'error', // Modern object property syntax
'prefer-arrow-callback': 'error', // Modern callback style
'no-duplicate-imports': 'error', // Avoid duplicate imports
'no-useless-constructor': 'error', // Remove unnecessary constructors
'no-useless-return': 'error', // Remove unnecessary return statements
'prefer-const': 'error', // Enforce const for immutable bindings
'no-var': 'error', // Enforce let/const over var
'object-shorthand': 'error', // Modern object property syntax
'prefer-arrow-callback': 'error', // Modern callback style
'no-duplicate-imports': 'error', // Avoid duplicate imports
'no-useless-constructor': 'error', // Remove unnecessary constructors
'no-useless-return': 'error', // Remove unnecessary return statements
'max-lines': ['warn', 300]
},
ignores: [