Skip to content

Commit

Permalink
build: add eslint-plugin-perfectionist
Browse files Browse the repository at this point in the history
Use the recommended-natural configuration and autofix issues

Make sure eslint is also run with the `--fix` option by lint-staged
  • Loading branch information
matijs committed Oct 18, 2024
1 parent a7076ad commit 660a503
Show file tree
Hide file tree
Showing 13 changed files with 139 additions and 79 deletions.
2 changes: 1 addition & 1 deletion .husky/pre-commit
Original file line number Diff line number Diff line change
@@ -1 +1 @@
pnpm exec lint-staged
lint-staged
15 changes: 12 additions & 3 deletions eslint.config.mjs
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
import globals from 'globals';
import json from '@eslint/json';
import js from '@eslint/js';
import tseslint from 'typescript-eslint';
import json from '@eslint/json';
import eslintConfigPrettier from 'eslint-config-prettier';
import eslintPluginJsxA11y from 'eslint-plugin-jsx-a11y';
import eslintPluginPerfectionist from 'eslint-plugin-perfectionist';
import eslintPluginReact from 'eslint-plugin-react';
import globals from 'globals';
import tseslint from 'typescript-eslint';

export default tseslint.config(
{
Expand Down Expand Up @@ -35,8 +36,10 @@ export default tseslint.config(
...json.configs.recommended,
},
...tseslint.configs.recommended,
eslintPluginPerfectionist.configs['recommended-natural'],
{
files: ['**/*.tsx'],
ignores: ['**/*.test.tsx'],
...eslintPluginReact.configs.flat.recommended,
...eslintPluginReact.configs.flat['jsx-runtime'],
...eslintPluginJsxA11y.flatConfigs.strict,
Expand All @@ -47,5 +50,11 @@ export default tseslint.config(
'@typescript-eslint/no-require-imports': 'off',
},
},
{
files: ['**/*.test.ts', '**/*.test.tsx'],
languageOptions: {
globals: { ...globals.jest },
},
},
eslintConfigPrettier,
);
8 changes: 4 additions & 4 deletions lint-staged.config.mjs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
export default {
'*': 'prettier --ignore-unknown --write',
'*.{css,scss}': ['stylelint --allow-empty-input --fix', 'prettier --write'],
'*.{js,cjs,mjs,jsx,ts,tsx}': ['eslint --no-error-on-unmatched-pattern --fix', 'prettier --write'],
'*.{yml,yaml}': 'prettier --write',
'*.md': ['markdownlint', 'prettier --write'],
'package.json': 'npmPkgJsonLint --allowEmptyTargets',
'*.md': 'markdownlint',
'*.{js,cjs,mjs,json,jsx,mdx,ts,tsx}': 'eslint --no-error-on-unmatched-pattern',
'*.{css,scss}': 'stylelint --allow-empty-input',
};
16 changes: 8 additions & 8 deletions npmpackagejsonlint.config.cjs
Original file line number Diff line number Diff line change
@@ -1,4 +1,12 @@
module.exports = {
overrides: [
{
patterns: ['proprietary/**/package.json'],
rules: {
'valid-values-license': ['error', ['SEE LICENSE IN LICENSE.md']],
},
},
],
rules: {
'no-caret-version-dependencies': 'error',
'no-caret-version-devDependencies': 'error',
Expand All @@ -8,12 +16,4 @@ module.exports = {
'valid-values-license': ['error', ['EUPL-1.2']],
'valid-values-name-scope': ['error', ['@nl-design-system-candidate']],
},
overrides: [
{
patterns: ['proprietary/**/package.json'],
rules: {
'valid-values-license': ['error', ['SEE LICENSE IN LICENSE.md']],
},
},
],
};
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@
"eslint": "9.12.0",
"eslint-config-prettier": "9.1.0",
"eslint-plugin-jsx-a11y": "6.10.0",
"eslint-plugin-perfectionist": "3.9.1",
"eslint-plugin-react": "7.37.1",
"globals": "15.11.0",
"husky": "9.1.6",
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import '@testing-library/jest-dom';
import { render } from '@testing-library/react';

import { Paragraph } from './paragraph';

describe('Paragraph', () => {
Expand Down
3 changes: 2 additions & 1 deletion packages/components-react/paragraph-react/src/paragraph.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import type { HTMLAttributes } from 'react';

import { clsx } from 'clsx';
import { forwardRef } from 'react';
import type { HTMLAttributes } from 'react';

export interface ParagraphProps extends HTMLAttributes<HTMLParagraphElement> {
appearance?: 'lead' | 'small';
Expand Down
10 changes: 5 additions & 5 deletions packages/storybook/config/main.ts
Original file line number Diff line number Diff line change
@@ -1,25 +1,25 @@
import type { StorybookConfig } from '@storybook/react-vite';

const config: StorybookConfig = {
stories: ['../src/**/*stories.@(js|jsx|ts|tsx)', '../src/**/*.mdx'],
addons: [
'@storybook/addon-a11y',
'@storybook/addon-docs',
'@storybook/addon-viewport',
'@whitespace/storybook-addon-html',
'@etchteam/storybook-addon-status',
],
framework: {
name: '@storybook/react-vite',
options: {},
},
core: {
disableTelemetry: true,
disableWhatsNewNotifications: true,
},
docs: {
autodocs: 'tag',
},
framework: {
name: '@storybook/react-vite',
options: {},
},
stories: ['../src/**/*stories.@(js|jsx|ts|tsx)', '../src/**/*.mdx'],
};

export default config;
19 changes: 10 additions & 9 deletions packages/storybook/config/preview.ts
Original file line number Diff line number Diff line change
@@ -1,29 +1,31 @@
import type { Preview } from '@storybook/react';

import { ParametersArgsDecorator } from './ParametersArgsDecorator';

const preview: Preview = {
decorators: [ParametersArgsDecorator],
parameters: {
controls: { expanded: false },
options: { panelPosition: 'right' },
status: {
statuses: {
PRODUCTION: {
background: '#088008',
color: '#ffffff',
ALPHA: {
background: '#e0bc2e',
color: '#000000',
description:
'Used in production in a variety of situations, well tested, stable APIs, mostly patches and minor releases.',
'Used in prototypes and in projects that are still in development, breaking changes occur frequently and are not communicated.',
},
BETA: {
background: '#3065ee',
color: '#ffffff',
description:
'Used in production in a specific situation, evolving APIs based on feedback, breaking changes are still likely.',
},
ALPHA: {
background: '#e0bc2e',
color: '#000000',
PRODUCTION: {
background: '#088008',
color: '#ffffff',
description:
'Used in prototypes and in projects that are still in development, breaking changes occur frequently and are not communicated.',
'Used in production in a variety of situations, well tested, stable APIs, mostly patches and minor releases.',
},
'WORK IN PROGRESS': {
background: '#cc0000',
Expand All @@ -34,7 +36,6 @@ const preview: Preview = {
},
},
},
decorators: [ParametersArgsDecorator],
};

export default preview;
3 changes: 2 additions & 1 deletion packages/storybook/src/paragraph.stories.tsx
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
import type { Meta, StoryObj } from '@storybook/react';

import { Paragraph } from '../../components-react/paragraph-react/src/paragraph';

const meta = {
component: Paragraph,
args: {
children: 'Op brute wijze ving de schooljuf de quasi-kalme lynx.',
},
component: Paragraph,
} satisfies Meta<typeof Paragraph>;

export default meta;
Expand Down
46 changes: 46 additions & 0 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions prettier.config.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,6 @@
* @type {import('prettier').Config}
*/
export default {
printWidth: 120,
singleQuote: true,
overrides: [
{
files: ['*.yml', '*.yaml'],
Expand All @@ -18,4 +16,6 @@ export default {
},
},
],
printWidth: 120,
singleQuote: true,
};
Loading

0 comments on commit 660a503

Please sign in to comment.