Merge pull request #147 from Shopify/@cartogram/eslint-fixes

fix: ESLint config fixes
This commit is contained in:
Matt Seccafien 2021-11-08 19:31:45 +01:00 committed by GitHub
commit cff98fa76c
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
10 changed files with 61 additions and 128 deletions

View file

@ -5,7 +5,11 @@ All notable changes to this project will be documented in this file.
The format is based on [Keep a Changelog](http://keepachangelog.com/en/1.0.0/)
and adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.html).
<!-- ## Unreleased -->
## Unreleased
- Added new `hydrogen/typescript` config
- Added `env#node: true` and `parserOptions#sourceType: 'module'` to core config
- Fixed issue requiring typescript to be install on non-typescript projects
## 0.6.0 - 2021-11-05

View file

@ -42,7 +42,6 @@
"ts-jest": "^26.5.4"
},
"peerDependencies": {
"@typescript-eslint/eslint-plugin": ">= 4",
"eslint": ">=5"
}
}

View file

@ -1,12 +0,0 @@
import rules from './rules';
export default {
plugins: ['hydrogen'],
extends: [
'plugin:@shopify/typescript',
'plugin:@shopify/react',
'plugin:@shopify/node',
'plugin:@shopify/prettier',
],
rules,
};

View file

@ -1,12 +0,0 @@
import rules from './rules';
export default {
plugins: ['hydrogen'],
extends: [
'plugin:@shopify/esnext',
'plugin:@shopify/react',
'plugin:@shopify/node',
'plugin:@shopify/prettier',
],
rules,
};

View file

@ -1,4 +0,0 @@
export default {
'hydrogen/no-state-in-server-components': 'error',
'hydrogen/prefer-image-component': 'error',
};

View file

@ -1,5 +0,0 @@
import {deepMerge} from '@typescript-eslint/experimental-utils/dist/eslint-utils';
import overrides from './overrides';
import hydrogen from './hydrogen';
export default deepMerge(hydrogen, overrides);

View file

@ -1,45 +0,0 @@
export default {
// TODO: We may want to change the configuration for the following 3 rules
'jsx-a11y/click-events-have-key-events': 'off',
'jsx-a11y/no-noninteractive-element-interactions': 'off',
'react/jsx-filename-extension': ['error', {extensions: ['.tsx', '.jsx']}],
/**
* Rules below this line are intentionally disabled for different reasons
*/
// The following 2 rules are very strict and disabled here to lessen developer frustration
'@shopify/jsx-no-hardcoded-content': 'off',
'@shopify/jsx-no-complex-expressions': 'off',
/**
* eslint overrides
*/
// We often define GraphQL queries at the bottom of the file which would be a violation for this rule
'no-use-before-define': 'off',
// We agree that warning comments acceptable
'no-warning-comments': 'off',
/**
* react overrides
*/
// Following Next.js and likely this will be the default in most frameworks
'react/react-in-jsx-scope': 'off',
// We default to typescript for typing, non typescript projects can override this rule if they want
'react/prop-types': 'off',
/**
* import overrides
*/
// TODO: We should turn these on, at least partially
// 'import/no-unresolved': ['off'],
// 'import/extensions': ['off'],
// These two rules result in a significant number of false positives so we
// need to keep them disabled.
'jsx-a11y/label-has-for': 'off',
'jsx-a11y/control-has-associated-label': 'off',
};

View file

@ -11,6 +11,7 @@ export default {
env: {
es2021: true,
browser: true,
node: true,
},
settings: {
react: {
@ -21,6 +22,7 @@ export default {
ecmaFeatures: {
jsx: true,
},
sourceType: 'module',
},
rules: {
'no-console': 'warn',
@ -39,54 +41,6 @@ export default {
},
ignorePatterns: ['node_modules/', 'build/', '*.graphql.d.ts', '*.graphql.ts'],
overrides: [
{
files: ['*.ts', '*.tsx'],
parser: '@typescript-eslint/parser',
extends: ['plugin:@typescript-eslint/recommended'],
rules: {
'react/prop-types': 'off',
'@typescript-eslint/no-explicit-any': 'off',
'@typescript-eslint/no-non-null-assertion': 'off',
'@typescript-eslint/explicit-module-boundary-types': 'off',
'@typescript-eslint/no-unused-vars': 'off',
'@typescript-eslint/no-empty-interface': 'off',
'@typescript-eslint/ban-types': [
'error',
{
types: {
String: {message: 'Use string instead', fixWith: 'string'},
Boolean: {message: 'Use boolean instead', fixWith: 'boolean'},
Number: {message: 'Use number instead', fixWith: 'number'},
Object: {message: 'Use object instead', fixWith: 'object'},
Array: {message: 'Provide a more specific type'},
ReadonlyArray: {message: 'Provide a more specific type'},
},
},
],
'@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'],
},
],
},
},
{
files: ['*.test.*'],
plugins: ['jest'],

View file

@ -0,0 +1,52 @@
export default {
overrides: [
{
files: ['*.ts', '*.tsx'],
parser: '@typescript-eslint/parser',
extends: ['plugin:@typescript-eslint/recommended'],
rules: {
'react/prop-types': 'off',
'@typescript-eslint/no-explicit-any': 'off',
'@typescript-eslint/no-non-null-assertion': 'off',
'@typescript-eslint/explicit-module-boundary-types': 'off',
'@typescript-eslint/no-unused-vars': 'off',
'@typescript-eslint/no-empty-interface': 'off',
'@typescript-eslint/ban-types': [
'error',
{
types: {
String: {message: 'Use string instead', fixWith: 'string'},
Boolean: {message: 'Use boolean instead', fixWith: 'boolean'},
Number: {message: 'Use number instead', fixWith: 'number'},
Object: {message: 'Use object instead', fixWith: 'object'},
Array: {message: 'Provide a more specific type'},
ReadonlyArray: {message: 'Provide a more specific type'},
},
},
],
'@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'],
},
],
},
},
],
};

View file

@ -1,9 +1,11 @@
import recommended from './configs/recommended';
import hydrogen from './configs/hydrogen';
import typescript from './configs/typescript';
export {rules} from './rules';
export const configs = {
recommended,
hydrogen,
typescript,
};