@shopify/cli
Version:
A CLI tool to build for the Shopify platform
248 lines (245 loc) • 6.22 kB
JavaScript
import {fixupConfigRules, fixupPluginRules} from '@eslint/compat';
import eslintComments from 'eslint-plugin-eslint-comments';
import react from 'eslint-plugin-react';
import reactHooks from 'eslint-plugin-react-hooks';
import jsxA11Y from 'eslint-plugin-jsx-a11y';
import globals from 'globals';
import typescriptEslint from '@typescript-eslint/eslint-plugin';
import _import from 'eslint-plugin-import';
import tsParser from '@typescript-eslint/parser';
import jest from 'eslint-plugin-jest';
import path from 'node:path';
import {fileURLToPath} from 'node:url';
import js from '@eslint/js';
import {FlatCompat} from '@eslint/eslintrc';
const __filename = fileURLToPath(import.meta.url);
const __dirname = path.dirname(__filename);
const compat = new FlatCompat({
baseDirectory: __dirname,
recommendedConfig: js.configs.recommended,
allConfig: js.configs.all,
});
export default [
{
ignores: [
'**/node_modules/',
'**/build/',
'**/dist/',
'**/*.graphql.d.ts',
'**/*.graphql.ts',
'**/*.generated.d.ts',
'**/.react-router/',
'**/packages/hydrogen/dist/',
],
},
...fixupConfigRules(
compat.extends(
'eslint:recommended',
'plugin:eslint-comments/recommended',
'plugin:react/recommended',
'plugin:react-hooks/recommended',
'plugin:jsx-a11y/recommended',
),
),
{
plugins: {
'eslint-comments': fixupPluginRules(eslintComments),
react: fixupPluginRules(react),
'react-hooks': fixupPluginRules(reactHooks),
'jsx-a11y': fixupPluginRules(jsxA11Y),
},
languageOptions: {
globals: {
...globals.browser,
...globals.node,
},
ecmaVersion: 'latest',
sourceType: 'module',
parserOptions: {
ecmaFeatures: {
jsx: true,
},
},
},
settings: {
react: {
version: 'detect',
},
},
rules: {
'eslint-comments/no-unused-disable': 'error',
'no-console': [
'warn',
{
allow: ['warn', 'error'],
},
],
'no-use-before-define': 'off',
'no-warning-comments': 'off',
'object-shorthand': [
'error',
'always',
{
avoidQuotes: true,
},
],
'no-useless-escape': 'off',
'no-case-declarations': 'off',
},
},
...fixupConfigRules(
compat.extends(
'plugin:react/recommended',
'plugin:react/jsx-runtime',
'plugin:react-hooks/recommended',
'plugin:jsx-a11y/recommended',
),
).map((config) => ({
...config,
files: ['**/*.{js,jsx,ts,tsx}'],
})),
{
files: ['**/*.{js,jsx,ts,tsx}'],
plugins: {
react: fixupPluginRules(react),
'jsx-a11y': fixupPluginRules(jsxA11Y),
},
settings: {
react: {
version: 'detect',
},
formComponents: ['Form'],
linkComponents: [
{
name: 'Link',
linkAttribute: 'to',
},
{
name: 'NavLink',
linkAttribute: 'to',
},
],
'import/resolver': {
typescript: {},
},
},
rules: {
'jsx-a11y/control-has-associated-label': 'off',
'jsx-a11y/label-has-for': 'off',
'react/display-name': 'off',
'react/no-array-index-key': 'warn',
'react/prop-types': 'off',
'react/react-in-jsx-scope': 'off',
},
},
...fixupConfigRules(
compat.extends(
'plugin:@typescript-eslint/recommended',
'plugin:import/recommended',
'plugin:import/typescript',
),
).map((config) => ({
...config,
files: ['**/*.{ts,tsx}'],
})),
{
files: ['**/*.{ts,tsx}'],
plugins: {
'@typescript-eslint': fixupPluginRules(typescriptEslint),
import: fixupPluginRules(_import),
},
languageOptions: {
parser: tsParser,
parserOptions: {
project: './tsconfig.json',
tsconfigRootDir: __dirname,
ecmaFeatures: {
jsx: true,
},
},
},
settings: {
'import/internal-regex': '^~/',
'import/resolvers': {
node: {
extensions: ['.ts', '.tsx'],
},
typescript: {
alwaysTryTypes: true,
project: __dirname,
},
},
},
rules: {
'@typescript-eslint/ban-ts-comment': 'off',
'@typescript-eslint/explicit-module-boundary-types': '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-empty-object-type': 'off',
'@typescript-eslint/no-explicit-any': 'off',
'@typescript-eslint/no-non-null-assertion': 'off',
'@typescript-eslint/no-non-null-asserted-optional-chain': 'off',
'@typescript-eslint/no-unused-vars': 'off',
'@typescript-eslint/no-floating-promises': 'error',
'@typescript-eslint/no-misused-promises': 'error',
'react/prop-types': 'off',
'import/no-unresolved': ['error', {ignore: ['^virtual:']}],
},
},
{
files: ['**/.eslintrc.cjs'],
languageOptions: {
globals: {
...globals.node,
},
},
},
...compat.extends('plugin:jest/recommended').map((config) => ({
...config,
files: ['**/*.test.*'],
})),
{
files: ['**/*.test.*'],
plugins: {
jest,
},
languageOptions: {
globals: {
...globals.node,
...globals.jest,
},
},
},
{
files: ['**/*.server.*'],
rules: {
'react-hooks/rules-of-hooks': 'off',
},
},
];