Skip to content

Commit

Permalink
chore(eslint): better v9 conversion - hydrogen-react
Browse files Browse the repository at this point in the history
  • Loading branch information
liady committed Jan 21, 2025
1 parent 086ab9c commit 4a2a258
Show file tree
Hide file tree
Showing 15 changed files with 185 additions and 123 deletions.
254 changes: 154 additions & 100 deletions packages/hydrogen-react/eslint.config.cjs
Original file line number Diff line number Diff line change
@@ -1,67 +1,81 @@
const typescriptParser = require('@typescript-eslint/parser');
const typescriptPlugin = require('@typescript-eslint/eslint-plugin');
const eslintJs = require('@eslint/js');
const eslintCommentsPlugin = require('@eslint-community/eslint-plugin-eslint-comments');
const reactPlugin = require('eslint-plugin-react');
const reactHooksPlugin = require('eslint-plugin-react-hooks');
const jsxA11yPlugin = require('eslint-plugin-jsx-a11y');
const prettierPlugin = require('eslint-plugin-prettier');
const nodePlugin = require('eslint-plugin-node');
const importPlugin = require('eslint-plugin-import');
const jestPlugin = require('eslint-plugin-jest');
const tsdocPlugin = require('eslint-plugin-tsdoc');
const simpleImportSortPlugin = require('eslint-plugin-simple-import-sort');
const {fixupPluginRules} = require('@eslint/compat');
const {fixupConfigRules, fixupPluginRules} = require('@eslint/compat');
const eslintComments = require('eslint-plugin-eslint-comments');
const react = require('eslint-plugin-react');
const reactHooks = require('eslint-plugin-react-hooks');
const jsxA11Y = require('eslint-plugin-jsx-a11y');
const tsdoc = require('eslint-plugin-tsdoc');
const globals = require('globals');
const tsParser = require('@typescript-eslint/parser');
const jest = require('eslint-plugin-jest');
const simpleImportSort = require('eslint-plugin-simple-import-sort');
const js = require('@eslint/js');
const {FlatCompat} = require('@eslint/eslintrc');

const compat = new FlatCompat({
baseDirectory: __dirname,
recommendedConfig: js.configs.recommended,
allConfig: js.configs.all,
});

/** @type {import('eslint').Flat.Config[]} */
module.exports = [
// Base configuration
{
ignores: [
'node_modules/',
'build/',
'*.graphql.d.ts',
'*.graphql.ts',
'**/node_modules/',
'**/build/',
'**/*.graphql.d.ts',
'**/*.graphql.ts',
'**/storefront-api-types.d.ts',
'**/customer-account-api-types.d.ts',
'**/codegen.ts',
'**/dist/**',
'**/coverage/**',
'**/docs/**',
'**/dist/**/*',
'**/coverage/**/*',
'**/docs/**/*',
'**/.eslintrc.cjs',
'**/src/*.example.tsx',
'**/src/*.example.ts',
'**/src/*.example.jsx',
'**/src/*.example.js',
'**/eslint.config.cjs',
'**/scripts/**/*',
],
},
// Default configuration for all files
...fixupConfigRules(
compat.extends(
'plugin:node/recommended',
'plugin:import/recommended',
'plugin:import/typescript',
'eslint:recommended',
'plugin:eslint-comments/recommended',
'plugin:react/recommended',
'plugin:react-hooks/recommended',
'plugin:jsx-a11y/recommended',
),
),
{
files: ['**/*.{js,jsx,ts,tsx}'],
...eslintJs.configs.recommended,
plugins: {
'eslint-comments': eslintCommentsPlugin,
react: reactPlugin,
'react-hooks': reactHooksPlugin,
'jsx-a11y': jsxA11yPlugin,
prettier: prettierPlugin,
node: fixupPluginRules(nodePlugin),
import: importPlugin,
'@typescript-eslint': typescriptPlugin,
tsdoc: tsdocPlugin,
'simple-import-sort': simpleImportSortPlugin,
'eslint-comments': fixupPluginRules(eslintComments),
react: fixupPluginRules(react),
'react-hooks': fixupPluginRules(reactHooks),
'jsx-a11y': fixupPluginRules(jsxA11Y),
tsdoc,
},
languageOptions: {
parser: typescriptParser,
parser: tsParser,
parserOptions: {
project: ['./tsconfig.json'],
tsconfigRootDir: '.',
projectService: {
allowDefaultProject: ['vite.config.ts', 'vitest.setup.ts'],
},
tsconfigRootDir: __dirname,
ecmaFeatures: {
jsx: true,
},
sourceType: 'module',
},
ecmaVersion: 2021,
globals: {
...globals.browser,
...globals.node,
},
ecmaVersion: 2020,
sourceType: 'module',
},
linterOptions: {
reportUnusedDisableDirectives: false,
Expand All @@ -75,27 +89,29 @@ module.exports = [
},
},
rules: {
// TypeScript
'@typescript-eslint/naming-convention': 'off',
'@typescript-eslint/explicit-module-boundary-types': 'off',
'@typescript-eslint/no-empty-function': 'off',
'@typescript-eslint/no-empty-interface': 'off',
'@typescript-eslint/no-explicit-any': 'error',
'@typescript-eslint/no-non-null-assertion': 'off',
'@typescript-eslint/no-unused-vars': 'off',

// React
'@shopify/jsx-no-complex-expressions': 'off',
'@shopify/jsx-no-hardcoded-content': 'off',
'jsx-a11y/control-has-associated-label': 'off',
'jsx-a11y/label-has-for': 'off',
'no-use-before-define': 'off',
'no-warning-comments': 'off',
'object-shorthand': [
'error',
'always',
{
avoidQuotes: true,
},
],
'react/display-name': 'off',
'react/no-array-index-key': 'warn',
'react/prop-types': 'off',
'react/react-in-jsx-scope': 'off',
'react-hooks/exhaustive-deps': 'error',

// A11y
'jsx-a11y/control-has-associated-label': 'off',
'jsx-a11y/label-has-for': 'off',

// Node
'eslint-comments/no-unused-disable': 'off',
'jest/no-disabled-tests': 'off',
'jest/no-export': 'off',
'no-console': 'off',
'no-constant-condition': 'off',
'tsdoc/syntax': 'error',
'node/no-extraneous-import': [
'error',
{
Expand Down Expand Up @@ -123,65 +139,106 @@ module.exports = [
ignores: [],
},
],
'node/no-missing-import': 'off',

// Import/Export
'prefer-const': [
'warn',
{
destructuring: 'all',
},
],
'@typescript-eslint/naming-convention': 'off',
'import/extensions': ['error', 'ignorePackages'],
'import/no-unresolved': 'off',
'simple-import-sort/exports': 'error',

// General
'no-console': 'off',
'no-use-before-define': 'off',
'no-warning-comments': 'off',
'no-constant-condition': 'off',
'object-shorthand': ['error', 'always', {avoidQuotes: true}],
'prefer-const': ['warn', {destructuring: 'all'}],

// Testing
'jest/no-disabled-tests': 'off',
'jest/no-export': 'off',

// Other
'eslint-comments/no-unused-disable': 'off',
'tsdoc/syntax': 'error',
'node/no-missing-import': 'off',
'react-hooks/exhaustive-deps': 'error',
},
},
// Test files configuration
...compat.extends('plugin:jest/recommended').map((config) => ({
...config,
files: ['**/*.test.*'],
})),
{
files: ['*.test.*'],
files: ['**/*.test.*'],
plugins: {
jest: jestPlugin,
},
rules: {
...jestPlugin.configs.recommended.rules,
jest,
},
languageOptions: {
globals: {
jest: true,
expect: true,
describe: true,
it: true,
beforeEach: true,
afterEach: true,
...globals.node,
...globals.jest,
},
},
},
// Server files configuration
{
files: ['*.server.*'],
files: ['**/*.server.*'],
rules: {
'react-hooks/rules-of-hooks': 'off',
},
},
// TypeScript files configuration
...fixupConfigRules(
compat.extends(
'plugin:@typescript-eslint/eslint-recommended',
'plugin:@typescript-eslint/recommended',
'plugin:@typescript-eslint/recommended-requiring-type-checking',
),
).map((config) => ({
...config,
files: ['**/*.ts', '**/*.tsx'],
languageOptions: {
parser: tsParser,
parserOptions: {
projectService: {
allowDefaultProject: ['vite.config.ts', 'vitest.setup.ts'],
},
tsconfigRootDir: __dirname,
ecmaFeatures: {
jsx: true,
},
},
},
})),
{
files: ['*.ts', '*.tsx'],
plugins: {
'@typescript-eslint': typescriptPlugin,
files: ['**/*.ts', '**/*.tsx'],
languageOptions: {
parser: tsParser,
parserOptions: {
projectService: {
allowDefaultProject: ['vite.config.ts', 'vitest.setup.ts'],
},
tsconfigRootDir: __dirname,
ecmaFeatures: {
jsx: true,
},
},
},
rules: {
'@typescript-eslint/explicit-module-boundary-types': 'off',
'@typescript-eslint/prefer-promise-reject-errors': 'off',
'@typescript-eslint/naming-convention': [
'error',
{
selector: 'default',
format: ['camelCase', 'PascalCase', 'UPPER_CASE'],
leadingUnderscore: 'allowSingleOrDouble',
trailingUnderscore: 'allowSingleOrDouble',
},
{
selector: 'typeLike',
format: ['PascalCase'],
},
{
selector: 'typeParameter',
format: ['PascalCase'],
leadingUnderscore: 'allow',
},
{
selector: 'interface',
format: ['PascalCase'],
},
{
selector: 'property',
format: null,
},
],
'@typescript-eslint/no-empty-function': 'off',
'@typescript-eslint/no-empty-interface': 'off',
'@typescript-eslint/no-explicit-any': 'off',
Expand All @@ -190,25 +247,22 @@ module.exports = [
'react/prop-types': 'off',
},
},
// Example files configuration
{
files: ['src/*.example.?(ts|js|tsx|jsx)'],
rules: {
'node/no-extraneous-import': 'off',
'node/no-extraneous-require': 'off',
},
},
// Index.ts configuration
{
files: ['src/index.ts'],
plugins: {
'simple-import-sort': simpleImportSortPlugin,
'simple-import-sort': simpleImportSort,
},
rules: {
'simple-import-sort/exports': 'error',
},
},
// Source files configuration (excluding tests, examples, etc.)
{
files: ['src/**/!(*.test|*.example|*.doc|*.stories).?(ts|js|tsx|jsx)'],
rules: {
Expand Down
2 changes: 2 additions & 0 deletions packages/hydrogen-react/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -133,6 +133,7 @@
"devDependencies": {
"@eslint-community/eslint-plugin-eslint-comments": "^4.4.1",
"@eslint/compat": "^1.2.5",
"@eslint/eslintrc": "^3.2.0",
"@eslint/js": "^9.18.0",
"@faker-js/faker": "^7.6.0",
"@graphql-codegen/add": "^5.0.1",
Expand Down Expand Up @@ -161,6 +162,7 @@
"eslint-plugin-react-hooks": "^5.1.0",
"eslint-plugin-simple-import-sort": "^12.1.1",
"eslint-plugin-tsdoc": "^0.4.0",
"globals": "^15.14.0",
"happy-dom": "8.7.2",
"npm-run-all": "^4.1.5",
"prettier": "^3.4.2",
Expand Down
2 changes: 1 addition & 1 deletion packages/hydrogen-react/src/CartCheckoutButton.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ export function CartCheckoutButton(

// This is only for documentation purposes, and it is not used in the code.
// we ignore this issue because it makes the documentation look better than the equivalent `type` that it wants us to convert to
// eslint-disable-next-line @typescript-eslint/no-empty-interface
// eslint-disable-next-line @typescript-eslint/no-empty-object-type
export interface CartCheckoutButtonPropsForDocs<
AsType extends React.ElementType = 'button',
> extends Omit<CustomBaseButtonProps<AsType>, 'onClick'> {}
1 change: 0 additions & 1 deletion packages/hydrogen-react/src/Image.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
/* eslint-disable eslint-comments/disable-enable-pair */
/* eslint-disable @typescript-eslint/explicit-function-return-type */
/* eslint-disable hydrogen/prefer-image-component */
import * as React from 'react';
import type {PartialDeep} from 'type-fest';
import type {Image as ImageType} from './storefront-api-types.js';
Expand Down
2 changes: 1 addition & 1 deletion packages/hydrogen-react/src/ModelViewer.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@ export function ModelViewer(props: ModelViewerProps): JSX.Element | null {
},
);

return () => {
return (): void => {
if (modelViewer == null) {
return;
}
Expand Down
Loading

0 comments on commit 4a2a258

Please sign in to comment.