diff --git a/.github/workflows/lint-format.yml b/.github/workflows/lint-format.yml new file mode 100644 index 00000000..1e979312 --- /dev/null +++ b/.github/workflows/lint-format.yml @@ -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.' + }) diff --git a/.prettierrc b/.prettierrc index 6c1b0bda..687fb83d 100644 --- a/.prettierrc +++ b/.prettierrc @@ -1,5 +1,5 @@ { - "printWidth": 120, + "printWidth": 150, "tabWidth": 2, "useTabs": false, "semi": true, diff --git a/eslint.config.js b/eslint.config.js index d091150d..23ee5805 100644 --- a/eslint.config.js +++ b/eslint.config.js @@ -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: [