Repository navigation
test: ESLint設定とpost-hooksの不足テストを追加 #803
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
Merged
Merged
Changes from 1 commit
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,273 @@ | ||
| 'use strict'; | ||
|
|
||
| const fs = require('fs'); | ||
| const path = require('path'); | ||
|
|
||
| const repoPath = path.resolve(__dirname, '..'); | ||
|
|
||
| describe('eslint.config.mjs — root ESLint configuration', () => { | ||
| const filePath = path.join(repoPath, 'eslint.config.mjs'); | ||
| let content; | ||
|
|
||
| beforeAll(() => { | ||
| content = fs.readFileSync(filePath, 'utf8'); | ||
| }); | ||
|
|
||
| describe('File structure', () => { | ||
| test('should exist', () => { | ||
| expect(fs.existsSync(filePath)).toBe(true); | ||
| }); | ||
|
|
||
| test('should be an ES module (.mjs)', () => { | ||
| expect(filePath).toMatch(/\.mjs$/); | ||
| }); | ||
|
|
||
| test('should use default export', () => { | ||
| expect(content).toContain('export default'); | ||
| }); | ||
|
|
||
| test('should import @eslint/js', () => { | ||
| expect(content).toContain("from '@eslint/js'"); | ||
| }); | ||
|
|
||
| test('should import globals', () => { | ||
| expect(content).toContain("from 'globals'"); | ||
| }); | ||
|
|
||
| test('should import eslint-config-prettier', () => { | ||
| expect(content).toContain("from 'eslint-config-prettier'"); | ||
| }); | ||
| }); | ||
|
|
||
| describe('Ignores configuration', () => { | ||
| test('should define an ignores entry', () => { | ||
| expect(content).toContain('ignores:'); | ||
| }); | ||
|
|
||
| test('should ignore node_modules', () => { | ||
| expect(content).toContain('node_modules/'); | ||
| }); | ||
|
|
||
| test('should ignore dist directory', () => { | ||
| expect(content).toContain('dist/'); | ||
| }); | ||
|
|
||
| test('should ignore coverage directory', () => { | ||
| expect(content).toContain('coverage/'); | ||
| }); | ||
|
|
||
| test('should ignore templates directory', () => { | ||
| expect(content).toContain("'templates/'"); | ||
| }); | ||
|
|
||
| test('should ignore minified files', () => { | ||
| expect(content).toContain('*.min.js'); | ||
| }); | ||
| }); | ||
|
|
||
| describe('Language options', () => { | ||
| test('should target files with js and jsx extensions', () => { | ||
| expect(content).toContain("'**/*.{js,jsx}'"); | ||
| }); | ||
|
|
||
| test('should set ecmaVersion to 2022 or later', () => { | ||
| expect(content).toMatch(/ecmaVersion:\s*202[2-9]/); | ||
| }); | ||
|
|
||
| test('should set sourceType to module', () => { | ||
| expect(content).toContain("sourceType: 'module'"); | ||
| }); | ||
|
|
||
| test('should include Node.js globals', () => { | ||
| expect(content).toContain('globals.node'); | ||
| }); | ||
|
|
||
| test('should include Jest globals', () => { | ||
| expect(content).toContain('globals.jest'); | ||
| }); | ||
| }); | ||
|
|
||
| describe('Rule configuration', () => { | ||
| test('should allow console usage (no-console: off)', () => { | ||
| expect(content).toContain("'no-console': 'off'"); | ||
| }); | ||
|
|
||
| test('should error on unused vars (with underscore exception)', () => { | ||
| expect(content).toContain("'no-unused-vars'"); | ||
| expect(content).toContain("argsIgnorePattern: '^_'"); | ||
| }); | ||
|
|
||
| test('should include complexity rule with max 15', () => { | ||
| expect(content).toContain('complexity:'); | ||
| expect(content).toContain('max: 15'); | ||
| }); | ||
|
|
||
| test('should include max-lines-per-function rule with max 100', () => { | ||
| expect(content).toContain("'max-lines-per-function'"); | ||
| expect(content).toContain('max: 100'); | ||
| }); | ||
|
|
||
| test('should include max-lines rule with max 500', () => { | ||
| expect(content).toContain("'max-lines'"); | ||
| expect(content).toContain('max: 500'); | ||
| }); | ||
|
|
||
| test('should include max-depth rule', () => { | ||
| expect(content).toContain("'max-depth'"); | ||
| }); | ||
|
|
||
| test('should include max-params rule with max 5', () => { | ||
| expect(content).toContain("'max-params'"); | ||
| expect(content).toContain("'warn', 5"); | ||
| }); | ||
|
|
||
| test('should include max-nested-callbacks rule', () => { | ||
| expect(content).toContain("'max-nested-callbacks'"); | ||
| }); | ||
|
|
||
| test('should use warn severity for complexity rules (Phase 1 strategy)', () => { | ||
| // All complexity rules should use 'warn' not 'error' | ||
| const warnMatches = content.match(/'warn'/g); | ||
| expect(warnMatches).not.toBeNull(); | ||
| expect(warnMatches.length).toBeGreaterThanOrEqual(5); | ||
| }); | ||
| }); | ||
|
|
||
| describe('Test file overrides', () => { | ||
| test('should have a config block targeting test files', () => { | ||
| expect(content).toContain("'**/*.test.js'"); | ||
| }); | ||
|
|
||
| test('should also target spec files', () => { | ||
| expect(content).toContain("'**/*.spec.js'"); | ||
| }); | ||
|
|
||
| test('should also target files under test/ directory', () => { | ||
| expect(content).toContain("'**/test/**/*.js'"); | ||
| }); | ||
|
|
||
| test('should disable max-lines-per-function for test files', () => { | ||
| expect(content).toContain("'max-lines-per-function': 'off'"); | ||
| }); | ||
|
|
||
| test('should relax max-nested-callbacks limit for test files', () => { | ||
| // Test files need more nesting for describe/test/beforeAll etc. | ||
| expect(content).toContain("'max-nested-callbacks': ['warn', 5]"); | ||
| }); | ||
| }); | ||
|
|
||
| describe('Consistency with complexity-rules.mjs template', () => { | ||
| const templatePath = path.join(repoPath, 'eslint', 'complexity-rules.mjs'); | ||
| let template; | ||
|
|
||
| beforeAll(() => { | ||
| template = fs.readFileSync(templatePath, 'utf8'); | ||
| }); | ||
|
|
||
| test('both files should use the same cyclomatic complexity limit (15)', () => { | ||
| const rootMatch = content.match(/complexity:.*?\n.*?max:\s*(\d+)/s); | ||
| const templateMatch = template.match(/complexity:.*?\n.*?max:\s*(\d+)/s); | ||
| expect(rootMatch).not.toBeNull(); | ||
| expect(templateMatch).not.toBeNull(); | ||
| expect(rootMatch[1]).toBe(templateMatch[1]); | ||
| }); | ||
|
|
||
| test('both files should use the same max-lines-per-function limit (100)', () => { | ||
| // Both files should reference max: 100 for max-lines-per-function | ||
| expect(content).toContain('max: 100'); | ||
| expect(template).toContain('max: 100'); | ||
| }); | ||
|
|
||
| test('both files should use the same max-lines limit (500)', () => { | ||
| expect(content).toContain('max: 500'); | ||
| expect(template).toContain('max: 500'); | ||
| }); | ||
| }); | ||
| }); | ||
|
|
||
| describe('templates/eslint/eslint.config.mjs — TypeScript/Next.js ESLint template', () => { | ||
| const filePath = path.join(repoPath, 'templates', 'eslint', 'eslint.config.mjs'); | ||
| let content; | ||
|
|
||
| beforeAll(() => { | ||
| content = fs.readFileSync(filePath, 'utf8'); | ||
| }); | ||
|
|
||
| describe('File structure', () => { | ||
| test('should exist', () => { | ||
| expect(fs.existsSync(filePath)).toBe(true); | ||
| }); | ||
|
|
||
| test('should be an ES module (.mjs)', () => { | ||
| expect(filePath).toMatch(/\.mjs$/); | ||
| }); | ||
|
|
||
| test('should use default export', () => { | ||
| expect(content).toContain('export default'); | ||
| }); | ||
|
|
||
| test('should import typescript-eslint', () => { | ||
| expect(content).toContain("from 'typescript-eslint'"); | ||
| }); | ||
| }); | ||
|
|
||
| describe('Ignores configuration', () => { | ||
| test('should ignore node_modules', () => { | ||
| expect(content).toContain('node_modules/**'); | ||
| }); | ||
|
|
||
| test('should ignore .next directory', () => { | ||
| expect(content).toContain('.next/**'); | ||
| }); | ||
|
|
||
| test('should ignore dist directory', () => { | ||
| expect(content).toContain('dist/**'); | ||
| }); | ||
|
|
||
| test('should ignore build directory', () => { | ||
| expect(content).toContain('build/**'); | ||
| }); | ||
|
|
||
| test('should ignore coverage directory', () => { | ||
| expect(content).toContain('coverage/**'); | ||
| }); | ||
| }); | ||
|
|
||
| describe('TypeScript configuration', () => { | ||
| test('should use tseslint.configs.recommended spread', () => { | ||
| expect(content).toContain('...tseslint.configs.recommended'); | ||
| }); | ||
|
|
||
| test('should target TypeScript files', () => { | ||
| expect(content).toContain("'**/*.{ts,tsx}'"); | ||
| }); | ||
|
|
||
| test('should configure @typescript-eslint/no-unused-vars', () => { | ||
| expect(content).toContain('@typescript-eslint/no-unused-vars'); | ||
| }); | ||
|
|
||
| test('should allow underscore-prefixed unused variables', () => { | ||
| expect(content).toContain("argsIgnorePattern: '^_'"); | ||
| expect(content).toContain("varsIgnorePattern: '^_'"); | ||
| }); | ||
| }); | ||
|
|
||
| describe('Documentation and usage hints', () => { | ||
| test('should include usage instructions in comments', () => { | ||
| expect(content).toContain('使い方'); | ||
| }); | ||
|
|
||
| test('should reference complexity-rules.mjs for complexity guards', () => { | ||
| expect(content).toContain('complexity-rules.mjs'); | ||
| }); | ||
|
|
||
| test('should have commented-out complexityRules import (opt-in)', () => { | ||
| // The complexity rules import should be commented out (opt-in pattern) | ||
| expect(content).toContain('// import { complexityRules }'); | ||
| }); | ||
|
|
||
| test('should have commented-out Next.js config (opt-in)', () => { | ||
| expect(content).toContain('// import nextCoreWebVitals'); | ||
| }); | ||
| }); | ||
| }); | ||
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This regex skips the actual cyclomatic complexity limit because both configs define it inline as
complexity: ['warn', { max: 15 }]; requiring a newline beforemaxmakes the match continue into the next rule and capturemax: 100frommax-lines-per-functioninstead. As a result, changing either complexity limit away from 15 would not be caught as long as both files still have the same function-length limit, so the new regression test does not protect the behavior it names.Useful? React with 👍 / 👎.