Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 10 additions & 0 deletions .changeset/calm-rules-warn.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
---
'@frontify/oxlint-config-basic': minor
'@frontify/oxlint-config-react': minor
---

Report nested ternaries, redundant `else` branches, array `reduce`, and lint exceptions without a reason as errors. Apply the existing errors for empty blocks and redundant catch clauses to TypeScript. Require an explicit switch case for every member of a TypeScript union.

Check existing JSDoc for summaries and tag formatting. If a documented function has a parameter or destructured prop with a default, include an `@default` tag with its value. Keep JSDoc types in JavaScript and use TypeScript annotations in TypeScript.

Warn about function complexity, nesting depth, parameter count, and parameter mutation. Tests and stories omit those warnings and the errors for nested ternaries and redundant `else` branches.
104 changes: 82 additions & 22 deletions packages/oxlint-config-basic/index.mjs
Original file line number Diff line number Diff line change
@@ -1,10 +1,22 @@
/* (c) Copyright Frontify Ltd., all rights reserved. */

import { fileURLToPath } from 'node:url';

import { defineConfig } from 'oxlint';

const TEST_FILES = ['**/*.test.{ts,tsx,js,jsx}', '**/*.spec.{ts,tsx,js,jsx}', '**/*.spec.{cy,ct}.{ts,tsx,js,jsx}'];
const FUNCTIONS_WITH_DEFAULTS =
':function:has(> AssignmentPattern, > ObjectPattern:has(> Property[value.type="AssignmentPattern"]))';
const DEFAULT_VALUE_TEXT = '\\S';
const DEFAULT_VALUE_MESSAGE = 'Add the default value after @default.';

export default defineConfig({
plugins: ['typescript', 'eslint', 'promise', 'unicorn', 'import'],
jsPlugins: ['@eslint-community/eslint-plugin-eslint-comments'],
plugins: ['typescript', 'eslint', 'promise', 'unicorn', 'import', 'jsdoc'],
jsPlugins: [
'@eslint-community/eslint-plugin-eslint-comments',
// Resolve from this package so consumers can use isolated installs.
{ name: 'jsdoc-js', specifier: fileURLToPath(import.meta.resolve('eslint-plugin-jsdoc')) },
],
categories: {
correctness: 'off',
},
Expand Down Expand Up @@ -49,6 +61,7 @@ export default defineConfig({
'@eslint-community/eslint-comments/no-duplicate-disable': 'error',
'@eslint-community/eslint-comments/no-unlimited-disable': 'error',
'@eslint-community/eslint-comments/no-unused-enable': 'error',
'@eslint-community/eslint-comments/require-description': 'error',
'typescript/await-thenable': 'error',
'typescript/ban-ts-comment': 'error',
'typescript/no-array-delete': 'error',
Expand Down Expand Up @@ -89,6 +102,48 @@ export default defineConfig({
'typescript/restrict-template-expressions': 'error',
'typescript/triple-slash-reference': 'error',
'typescript/unbound-method': 'error',
// Size and mutation rules warn until consumers are clean; the rest are errors.
complexity: ['warn', { max: 10 }],
'max-depth': ['warn', { max: 3 }],
'max-params': ['warn', { max: 3 }],
'no-else-return': 'error',
'no-nested-ternary': 'error',
'no-param-reassign': ['warn', { props: true }],
// JSDoc rules check existing blocks only: no block is required, and a summary-only block needs no @param.
'jsdoc/check-tag-names': 'error',
'jsdoc/no-defaults': 'error',
'jsdoc/require-param': ['error', { ignoreWhenAllParamsMissing: true }],
'jsdoc/require-param-description': 'error',
'jsdoc/require-returns-description': 'error',
'jsdoc-js/check-param-names': 'error',
'jsdoc-js/require-hyphen-before-param-description': 'error',
'jsdoc-js/require-description': [
'error',
{
contexts: [
'ArrowFunctionExpression',
'FunctionDeclaration',
'FunctionExpression',
'ClassDeclaration',
'VariableDeclaration',
'TSTypeAliasDeclaration',
'TSInterfaceDeclaration',
'TSPropertySignature',
'PropertyDefinition',
],
exemptedBy: ['inheritdoc', 'type'],
},
],
'jsdoc-js/require-tags': ['error', { tags: [{ tag: 'default', context: FUNCTIONS_WITH_DEFAULTS }] }],
'jsdoc-js/match-description': [
'error',
{
contexts: ['any'],
mainDescription: false,
nonemptyTags: false,
tags: { default: { match: DEFAULT_VALUE_TEXT, message: DEFAULT_VALUE_MESSAGE } },
},
],
},
overrides: [
{
Expand All @@ -112,7 +167,6 @@ export default defineConfig({
'no-dupe-else-if': 'error',
'no-dupe-keys': 'error',
'no-duplicate-case': 'error',
'no-empty': 'error',
'no-empty-character-class': 'error',
'no-empty-pattern': 'error',
'no-empty-static-block': 'error',
Expand Down Expand Up @@ -145,7 +199,6 @@ export default defineConfig({
'no-unused-labels': 'error',
'no-unused-private-class-members': 'error',
'no-useless-backreference': 'error',
'no-useless-catch': 'error',
'no-useless-escape': 'error',
'no-with': 'error',
'preserve-caught-error': 'error',
Expand Down Expand Up @@ -440,6 +493,8 @@ export default defineConfig({
node: true,
},
rules: {
'no-empty': 'error',
'no-useless-catch': 'error',
'prefer-template': 'error',
'no-var': 'error',
eqeqeq: 'error',
Expand Down Expand Up @@ -492,6 +547,7 @@ export default defineConfig({
'unicorn/throw-new-error': 'error',
'unicorn/prefer-node-protocol': 'error',
'unicorn/no-array-for-each': 'error',
'unicorn/no-array-reduce': 'error',
'unicorn/custom-error-definition': 'error',
'unicorn/explicit-length-check': 'error',
'unicorn/no-await-expression-member': 'error',
Expand Down Expand Up @@ -537,6 +593,9 @@ export default defineConfig({
'typescript/restrict-plus-operands': 'error',
'typescript/restrict-template-expressions': 'error',
'typescript/unbound-method': 'off',
// TypeScript carries the types; in plain JS, JSDoc braces are the only type information.
'jsdoc-js/no-types': 'error',
'typescript/switch-exhaustiveness-check': 'error',
'typescript/consistent-type-imports': [
'error',
{ prefer: 'type-imports', fixStyle: 'inline-type-imports' },
Expand Down Expand Up @@ -645,31 +704,32 @@ export default defineConfig({
},
},
{
files: [
'**/*.test.ts',
'**/*.test.tsx',
'**/*.test.js',
'**/*.test.jsx',
'**/*.spec.ts',
'**/*.spec.tsx',
'**/*.spec.js',
'**/*.spec.jsx',
'**/*.spec.cy.ts',
'**/*.spec.cy.tsx',
'**/*.spec.cy.js',
'**/*.spec.cy.jsx',
'**/*.spec.ct.ts',
'**/*.spec.ct.tsx',
'**/*.spec.ct.js',
'**/*.spec.ct.jsx',
],
files: TEST_FILES,
rules: {
'no-unused-expressions': 'off',
'no-only-tests/no-only-tests': 'error',
'typescript/unbound-method': 'off',
},
jsPlugins: ['eslint-plugin-no-only-tests'],
},
{
// Tests and stories favour readable, inline fixtures over small, flat functions.
files: [...TEST_FILES, '**/*.stories.{ts,tsx,js,jsx}'],
rules: {
// A test or story callback holds a whole scenario, so it branches more than production code.
complexity: 'off',
// describe, it and render callbacks nest by design.
'max-depth': 'off',
// Test helpers and story renderers mirror the signature of the API they exercise.
'max-params': 'off',
// Mock implementations read as a list of cases.
'no-else-return': 'off',
// Story args pick a variant inline in one expression.
'no-nested-ternary': 'off',
// Mocks and fixtures set up the objects they are handed.
'no-param-reassign': 'off',
},
},
{
files: ['**/*.ts', '**/*.tsx', '**/*.mts', '**/*.cts'],
rules: {
Expand Down
1 change: 1 addition & 0 deletions packages/oxlint-config-basic/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
"dependencies": {
"@eslint-community/eslint-plugin-eslint-comments": "^4.7.2",
"@stylistic/eslint-plugin": "^5.10.0",
"eslint-plugin-jsdoc": "^65.4.5",
"eslint-plugin-jsonc": "^3.2.0",
"eslint-plugin-no-only-tests": "^3.4.0",
"eslint-plugin-yml": "^3.4.0"
Expand Down
Loading