Repository navigation
feat(eslint-config-base): fully incorporate eslint-config-airbnb-base #267
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
Draft
literat
wants to merge
13
commits into
main
Choose a base branch
from
feat/eslint-v9-migrate
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Draft
Changes from all commits
Commits
Show all changes
13 commits
Select commit
Hold shift + click to select a range
2bced78
Fix(eslint-config-base): Use proper names for rules
literat 82a735d
Fix(eslint-config-react): Format rules properly into arrays
literat 0fef3b0
Fix(eslint-config-typescript): Use properly recommended config in fla…
literat 5c1ced4
Fix(eslint-config-jest): Remove duplicated use of plugin
literat d474e3c
Fix(eslint-config-base): Remove deprecated new line before return rule
literat 44e648b
Fix(eslint-config-react): Normalize flat format and config extends
literat 3678a2c
Refactor(eslint-config-base): Incorporate `eslint-config-airbnb-base`…
literat 3b2de5d
fix(eslint-config-base): fix corrupted no-mixed-operators groups
literat 6e16355
refactor(eslint-config-base): add missing airbnb-base style rules
literat f905acd
refactor(eslint-config-base): make whitespace.js native flat config
literat 0a14986
test(eslint-config-base): add test suite for base, legacy, optional, …
literat b37d14b
chore(repo): exclude test fixtures from self-lint and formatting
literat 07d1866
fix(eslint-config-base): remove duplicate rules from style.js
literat 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 |
|---|---|---|
| @@ -1,3 +1,6 @@ | ||
| # Handlebars partials are not supported yet | ||
| # @see https://github.com/prettier/prettier/issues/11834 | ||
| *.hbs | ||
|
|
||
| # Test fixtures are intentionally invalid/non-standard and shouldn't be reformatted | ||
| **/__tests__/__fixtures__/** |
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
7 changes: 7 additions & 0 deletions
7
packages/eslint-config-base/__tests__/__fixtures__/invalid.js
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,7 @@ | ||
| var mask = 1 & 2; | ||
|
|
||
| if (mask == 1) mask = 0; | ||
|
|
||
| for (const key in { a: 1 }) { | ||
| mask += key.length; | ||
| } |
9 changes: 9 additions & 0 deletions
9
packages/eslint-config-base/__tests__/__fixtures__/legacy-valid.js
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,9 @@ | ||
| var sum = function sum (a, b) { | ||
|
|
||
| 'use strict'; | ||
|
|
||
| return a + b; | ||
|
|
||
| }; | ||
|
|
||
| sum(1, 2); | ||
28 changes: 28 additions & 0 deletions
28
packages/eslint-config-base/__tests__/__fixtures__/valid.js
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,28 @@ | ||
| export function sum (a, b) { | ||
|
|
||
| return a + b; | ||
|
|
||
|
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Here should not be an empty line |
||
| } | ||
|
|
||
| export class Counter { | ||
|
|
||
| constructor (start) { | ||
|
|
||
| this.value = start; | ||
|
|
||
| } | ||
|
|
||
| increment () { | ||
|
|
||
| this.value += 1; | ||
|
|
||
| return this.value; | ||
|
|
||
| } | ||
|
|
||
| } | ||
|
|
||
| const numbers = [1, 2, 3]; | ||
| const doubled = numbers.map((number) => number * 2); | ||
|
|
||
| export default doubled; | ||
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,115 @@ | ||
| import assert from 'node:assert/strict'; | ||
| import fs from 'node:fs'; | ||
| import { describe, it } from 'node:test'; | ||
| import { ESLint } from 'eslint'; | ||
| import baseConfig from '../index.js'; | ||
| import legacyConfig from '../legacy.js'; | ||
| import optionalConfig from '../optional.js'; | ||
| import whitespaceConfig from '../whitespace.js'; | ||
|
|
||
| const readFixture = (name) => fs.readFileSync(`./__tests__/__fixtures__/${name}`, 'utf-8'); | ||
|
|
||
|
|
||
| const lint = async (config, code) => { | ||
| const eslint = new ESLint({ | ||
| overrideConfigFile: true, | ||
| overrideConfig: config, | ||
| }); | ||
|
|
||
| const [result] = await eslint.lintText(code, { filePath: 'fixture.js' }); | ||
|
|
||
| return result; | ||
| }; | ||
|
|
||
| describe('@alma-oss/eslint-config-base', () => { | ||
| describe('flags no problems with valid code', () => { | ||
| it('has no errors or warnings', async () => { | ||
| const result = await lint(baseConfig, readFixture('valid.js')); | ||
|
|
||
| assert.equal(result.errorCount, 0); | ||
| assert.equal(result.warningCount, 0); | ||
| }); | ||
| }); | ||
|
|
||
| describe('flags problems with invalid code', () => { | ||
| it('flags airbnb rules inherited as-is', async () => { | ||
| const result = await lint(baseConfig, readFixture('invalid.js')); | ||
| const ruleIds = result.messages.map((message) => message.ruleId); | ||
|
|
||
| assert.ok(ruleIds.includes('no-var')); | ||
| assert.ok(ruleIds.includes('eqeqeq')); | ||
| assert.ok(ruleIds.includes('guard-for-in')); | ||
| }); | ||
|
|
||
| it('flags rules restored during the ESLint v9 style.js migration', async () => { | ||
| const result = await lint(baseConfig, readFixture('invalid.js')); | ||
| const noBitwise = result.messages.find((message) => message.ruleId === 'no-bitwise'); | ||
|
|
||
| assert.ok(noBitwise, 'expected no-bitwise to be reported'); | ||
| assert.equal(noBitwise.severity, 2); | ||
| }); | ||
|
|
||
| it('respects ALMA severity overrides instead of airbnb defaults', async () => { | ||
| const result = await lint(baseConfig, readFixture('invalid.js')); | ||
| const curly = result.messages.find((message) => message.ruleId === 'curly'); | ||
|
|
||
| assert.ok(curly, 'expected curly to be reported'); | ||
| assert.equal(curly.severity, 1, 'curly should be a warning, not an airbnb error'); | ||
| }); | ||
|
|
||
| it('does not forbid for-in loops, unlike airbnb', async () => { | ||
| const result = await lint(baseConfig, readFixture('invalid.js')); | ||
| const ruleIds = result.messages.map((message) => message.ruleId); | ||
|
|
||
| assert.ok(!ruleIds.includes('no-restricted-syntax')); | ||
| }); | ||
| }); | ||
| }); | ||
|
|
||
| describe('@alma-oss/eslint-config-base/legacy', () => { | ||
| it('lints ES5 code with no errors or warnings', async () => { | ||
| const result = await lint(legacyConfig, readFixture('legacy-valid.js')); | ||
|
|
||
| assert.equal(result.errorCount, 0); | ||
| assert.equal(result.warningCount, 0); | ||
| }); | ||
|
|
||
| it('requires strict mode, unlike the modern config', async () => { | ||
| const result = await lint(legacyConfig, 'var sum = function sum(a, b) { return a + b; };\n'); | ||
| const ruleIds = result.messages.map((message) => message.ruleId); | ||
|
|
||
| assert.ok(ruleIds.includes('strict')); | ||
| }); | ||
| }); | ||
|
|
||
| describe('@alma-oss/eslint-config-base/optional', () => { | ||
| it('loads and lints without throwing', async () => { | ||
| const result = await lint([...baseConfig, ...optionalConfig], readFixture('valid.js')); | ||
|
|
||
| assert.equal(typeof result.errorCount, 'number'); | ||
| }); | ||
|
|
||
| it('flags additional insights not enabled by the base config', async () => { | ||
| const result = await lint([...baseConfig, ...optionalConfig], 'const foo = Symbol();\n\nexport default foo;\n'); | ||
| const ruleIds = result.messages.map((message) => message.ruleId); | ||
|
|
||
| assert.ok(ruleIds.includes('symbol-description')); | ||
| }); | ||
|
Comment on lines
+91
to
+96
|
||
| }); | ||
|
|
||
| describe('@alma-oss/eslint-config-base/whitespace', () => { | ||
| it('keeps whitespace rules at error severity', async () => { | ||
| const result = await lint(whitespaceConfig, 'if (true) {\n\tconsole.log(1);\n}\n'); | ||
| const indent = result.messages.find((message) => message.ruleId === 'indent'); | ||
|
|
||
| assert.ok(indent, 'expected indent to be reported'); | ||
| assert.equal(indent.severity, 2); | ||
| }); | ||
|
|
||
| it('downgrades non-whitespace rules to warnings', async () => { | ||
| const result = await lint(whitespaceConfig, readFixture('invalid.js')); | ||
| const noVar = result.messages.find((message) => message.ruleId === 'no-var'); | ||
|
|
||
| assert.ok(noVar, 'expected no-var to be reported'); | ||
| assert.equal(noVar.severity, 1, 'no-var is not a whitespace rule, so it should be a warning'); | ||
| }); | ||
| }); | ||
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
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 |
|---|---|---|
| @@ -1,13 +1,78 @@ | ||
| import { FlatCompat } from '@eslint/eslintrc'; | ||
| import { fixupConfigRules } from '@eslint/compat'; | ||
|
|
||
| const compat = new FlatCompat(); | ||
| import importPlugin from 'eslint-plugin-import'; | ||
| import bestPractices from './rules/best-practices.js'; | ||
| import errors from './rules/errors.js'; | ||
| import node from './rules/node.js'; | ||
| import style from './rules/style.js'; | ||
| import variables from './rules/variables.js'; | ||
| import globs from './globs.js'; | ||
| import settings from './settings.js'; | ||
|
|
||
| export default [ | ||
| ...fixupConfigRules(compat.extends('eslint-config-airbnb-base/legacy')), | ||
| { | ||
| name: '@lmc-eu/eslint-config-base/legacy', | ||
| name: '@alma-oss/eslint-config-base/legacy', | ||
|
|
||
| plugins: { | ||
| import: importPlugin, | ||
| }, | ||
|
|
||
| languageOptions: { | ||
| ecmaVersion: 5, | ||
| sourceType: 'script', | ||
| }, | ||
|
|
||
| settings, | ||
|
|
||
| rules: {}, | ||
| }, | ||
| bestPractices, | ||
| errors, | ||
| node, | ||
| style, | ||
| variables, | ||
| { | ||
| name: '@alma-oss/eslint-config-base/legacy-overrides', | ||
| rules: { | ||
| // === AIRBNB LEGACY OVERRIDES === | ||
| // Legacy requires never trailing commas | ||
| 'comma-dangle': ['error', 'never'], | ||
|
|
||
| // Prefer numeric literals (off in legacy) | ||
| 'prefer-numeric-literals': 'off', | ||
|
|
||
| // Restrict some object properties | ||
| 'no-restricted-properties': [ | ||
| 'error', | ||
| { | ||
| object: 'arguments', | ||
| property: 'callee', | ||
| message: 'arguments.callee is deprecated', | ||
| }, | ||
| { | ||
| property: '__defineGetter__', | ||
| message: 'Please use Object.defineProperty instead.', | ||
| }, | ||
| { | ||
| property: '__defineSetter__', | ||
| message: 'Please use Object.defineProperty instead.', | ||
| }, | ||
| ], | ||
|
|
||
| // Allow var in legacy code | ||
| 'no-var': 'off', | ||
|
|
||
| // Allow prefer-object-spread in legacy code | ||
| 'prefer-object-spread': 'off', | ||
|
|
||
| // Require strict mode ('safe' allows function or global) | ||
| strict: ['error', 'safe'], | ||
| }, | ||
| }, | ||
| { | ||
| files: globs.configs, | ||
|
|
||
| rules: { | ||
| // Using process.env is encouraged in configuration files | ||
| 'node/no-process-env': 'off', | ||
| }, | ||
|
Comment on lines
+73
to
+76
|
||
| }, | ||
| ]; | ||
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
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
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.
I think here should not be the empty line