Skip to content

Commit

Permalink
chore: migrate to Eslint Stylistic
Browse files Browse the repository at this point in the history
Eslint has desided to deprecated their formatting rules. So for
formatting we will use a plugin, Eslint Stylistic to be able to use the
formatting rules.
  • Loading branch information
Anissa3005 committed Jan 31, 2024
1 parent 519f997 commit b10f3cc
Show file tree
Hide file tree
Showing 9 changed files with 692 additions and 125 deletions.
2 changes: 1 addition & 1 deletion __tests__/auth.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ describe('auth', () => {
})
})

export async function createTestUser() : Promise<{response: request.Response, testUserId: string}> {
export async function createTestUser() : Promise<{ response: request.Response, testUserId: string }> {
const requestData = {
formFields: [{
id: 'email',
Expand Down
223 changes: 117 additions & 106 deletions eslint.config.js
Original file line number Diff line number Diff line change
@@ -1,15 +1,16 @@
import globals from 'globals'
import ts from '@typescript-eslint/eslint-plugin'
import tsParser from '@typescript-eslint/parser'
import * as graphqlESLint from '@graphql-eslint/eslint-plugin'
import eslintJsPlugin from '@eslint/js'
import globals from "globals";
import ts from "@typescript-eslint/eslint-plugin";
import tsParser from "@typescript-eslint/parser";
import * as graphqlESLint from "@graphql-eslint/eslint-plugin";
import eslintJsPlugin from "@eslint/js";
import stylistic from "@stylistic/eslint-plugin";

const gqlSchemaPath = './src/typeDefs/schema.graphql'
const gqlSchemaPath = "./src/typeDefs/schema.graphql";

export default [
// GLOBAL configuration
{
ignores: ['dist/*']
ignores: ["dist/*"],
},
// TODO: get this linter working. For some reason, it's not picking up the schema file
// GraphQL Linter for Operations and Fragments within code files
Expand Down Expand Up @@ -42,26 +43,23 @@ export default [
{
// Setup GraphQL Parser
// files: ['src/**/*.{graphql,gql}'],
files: [
'__tests__/*.ts',
'src/*.ts'
],
files: ["__tests__/*.ts", "src/*.ts"],
plugins: {
'@graphql-eslint': graphqlESLint
"@graphql-eslint": graphqlESLint,
},
languageOptions: {
parser: graphqlESLint,
parserOptions: {
schema: gqlSchemaPath
}
schema: gqlSchemaPath,
},
},
rules: {
// ...graphqlESLint.flatConfigs['schema-recommended'].rules,
// '@graphql-eslint/no-hashtag-description': 'off'
// '@graphql-eslint/no-anonymous-operations': 'error',
// '@graphql-eslint/no-duplicate-fields': 'error',
// '@graphql-eslint/no-unreachable-types': 'error'
}
},
},
//TODO: get this linter working. Currently, when the linter runs, it wrecks the file with the wrong quotes
// JSON Linter
Expand Down Expand Up @@ -102,113 +100,126 @@ export default [
// sourceType: 'module',
globals: {
...globals.node,
...globals.es6
}
},
files: [
'__tests__/**/*.ts',
'src/**/*.ts',
'src/**/*.js',
],
plugins: {
'@typescript-eslint': ts,
ts
...globals.es6,
},
},
ignores: [
'src/typeDefs/gqlTypes.ts',
'typesgeneratorconfig.ts'
],
files: ["__tests__/**/*.ts", "src/**/*.ts", "src/**/*.js"],
plugins: { "@typescript-eslint": ts, ts, "@stylistic": stylistic },
ignores: ["src/typeDefs/gqlTypes.ts", "typesgeneratorconfig.ts"],
// 'off' or 0 - turn the rule off
// 'warn' or 1 - turn the rule on as a warning (doesn’t affect exit code)
// 'error' or 2 - turn the rule on as an error (exit code will be 1)
rules: {
// TS specific rules
...ts.configs['eslint-recommended'].rules,
...ts.configs["eslint-recommended"].rules,
...ts.configs.recommended.rules,
'@typescript-eslint/no-shadow': 'error',
'@typescript-eslint/no-unused-vars': 'error',
"@typescript-eslint/no-shadow": "error",
"@typescript-eslint/no-unused-vars": "error",

// JS specific rules
...eslintJsPlugin.configs.recommended.rules,
// HACK: this eslint core rule is turned off so that the typescript-eslint version can be used instead
'no-unused-vars': 'off',
'block-scoped-var': 'error',
complexity: ['error', { max: 40 }],
'consistent-return': 'error',
curly: 'error',
'dot-location': ['error', 'property'],
'dot-notation': ['error', { allowPattern: '^[a-z]+(_[a-z]+)+$' }],
'no-alert': 'error',
'no-multi-spaces': 'error',
'no-redeclare': 'error',
'no-unused-expressions': ['error', { allowShortCircuit: true, allowTernary: true }],
'vars-on-top': 'off',
yoda: ['error', 'never', { exceptRange: true }],
'no-console': 'error', // we should use the logger instead
"no-unused-vars": "off",
"block-scoped-var": "error",
complexity: ["error", { max: 40 }],
"consistent-return": "error",
curly: "error",
"dot-location": ["error", "property"],
"dot-notation": ["error", { allowPattern: "^[a-z]+(_[a-z]+)+$" }],
"no-alert": "error",
"no-multi-spaces": "error",
"no-redeclare": "error",
"no-unused-expressions": [
"error",
{ allowShortCircuit: true, allowTernary: true },
],
"vars-on-top": "off",
yoda: ["error", "never", { exceptRange: true }],
"no-console": "error", // we should use the logger instead

// Stylistic Issues and Opinions
'arrow-body-style': 'error',
'array-bracket-spacing': ['error', 'never'],
'arrow-parens': ['error', 'as-needed'],
'arrow-spacing': 'error',
'block-spacing': ['error', 'always'],
'brace-style': ['error', '1tbs', { allowSingleLine: true }],
camelcase: ['error', { allow: ['639_3'] }],
'comma-dangle': ['error', 'never'],
'comma-spacing': ['error', { before: false, after: true }],
'comma-style': 'error',
'computed-property-spacing': ['error', 'never'],
'function-paren-newline': ['error', 'consistent'],
indent: [
'error',
// arrow-body-style is not supported by @stylistic, TypeError said to use '@/arrow-body-style', so for now I have added it like that
"@/arrow-body-style": "error",
"@stylistic/quotes": ["error", "single"],
"@stylistic/array-bracket-spacing": ["error", "never"],
"@stylistic/arrow-parens": ["error", "as-needed"],
"@stylistic/arrow-spacing": "error",
"@stylistic/block-spacing": ["error", "always"],
"brace-style": ["error", "1tbs", { allowSingleLine: true }],
camelcase: ["error", { allow: ["639_3"] }],
"@stylistic/comma-dangle": ["error", "never"],
"@stylistic/comma-spacing": [
"error",
{ before: false, after: true },
],
"@stylistic/comma-style": "error",
"@stylistic/computed-property-spacing": ["error", "never"],
"@stylistic/function-paren-newline": ["error", "consistent"],
"@stylistic/indent": [
"error",
4,
{
MemberExpression: 1,
SwitchCase: 1,
ArrayExpression: 'first',
ArrayExpression: "first",
ObjectExpression: 1,
FunctionDeclaration: { parameters: 'off' },
FunctionDeclaration: { parameters: "off" },
VariableDeclarator: { var: 2, let: 2, const: 3 },
CallExpression: { arguments: 'first' }
}
CallExpression: { arguments: "first" },
},
],
"@stylistic/key-spacing": [
"error",
{ beforeColon: false, afterColon: true },
],
'key-spacing': ['error', { beforeColon: false, afterColon: true }],
'keyword-spacing': ['error', { before: true, after: true }],
'linebreak-style': ['error', 'unix'], // no carriage returns
'max-len': ['error', {
code: 120,
ignoreComments: true,
ignoreTrailingComments: true,
ignoreUrls: true,
ignoreStrings: true,
ignoreTemplateLiterals: true,
ignoreRegExpLiterals: true
}], // be friendly to laptops
'newline-after-var': 'error',
'require-atomic-updates': 'warn',
'no-constant-condition': 'error',
'no-dupe-class-members': 'error',
'no-lonely-if': 'error',
'no-multiple-empty-lines': ['error', { max: 1, maxEOF: 1 }],
'no-underscore-dangle': 'error',
'no-var': 'error',
'object-curly-newline': ['error', { consistent: true }],
'object-property-newline': ['error', { allowAllPropertiesOnSameLine: true }],
'object-shorthand': ['error', 'methods'],
'operator-linebreak': [0, 'before'],
'padded-blocks': ['error', 'never'],
'prefer-arrow-callback': 'error',
'prefer-const': 'error',
'prefer-spread': 'error',
'prefer-template': 'error',
'quote-props': ['error', 'as-needed'],
quotes: ['error', 'single', 'avoid-escape'],
semi: ['error', 'never'],
'semi-spacing': 'error',
'space-before-blocks': 'error',
'space-before-function-paren': ['error', { anonymous: 'never', named: 'never', asyncArrow: 'always' }],
'space-in-parens': 'error',
'space-infix-ops': 'error'
}
}
]
"@stylistic/keyword-spacing": [
"error",
{ before: true, after: true },
],
"@stylistic/linebreak-style": ["error", "unix"], // no carriage returns
"@stylistic/max-len": [
"error",
{
code: 120,
ignoreComments: true,
ignoreTrailingComments: true,
ignoreUrls: true,
ignoreStrings: true,
ignoreTemplateLiterals: true,
ignoreRegExpLiterals: true,
},
], // be friendly to laptops
"newline-after-var": "error",
"require-atomic-updates": "warn",
"no-constant-condition": "error",
"no-dupe-class-members": "error",
"no-lonely-if": "error",
"no-multiple-empty-lines": ["error", { max: 1, maxEOF: 1 }],
"no-underscore-dangle": "error",
"no-var": "error",
"object-curly-newline": ["error", { consistent: true }],
"object-property-newline": [
"error",
{ allowAllPropertiesOnSameLine: true },
],
"object-shorthand": ["error", "methods"],
"operator-linebreak": [0, "before"],
"padded-blocks": ["error", "never"],
"prefer-arrow-callback": "error",
"prefer-const": "error",
"prefer-spread": "error",
"prefer-template": "error",
"quote-props": ["error", "as-needed"],
quotes: ["error", "single", "avoid-escape"],
semi: ["error", "never"],
"semi-spacing": "error",
"space-before-blocks": "error",
"space-before-function-paren": [
"error",
{ anonymous: "never", named: "never", asyncArrow: "always" },
],
"space-in-parens": "error",
"space-infix-ops": "error",
},
},
];
Loading

0 comments on commit b10f3cc

Please sign in to comment.