Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Linting #1337

Merged
merged 15 commits into from
Mar 9, 2023
7 changes: 6 additions & 1 deletion .babelrc.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,12 @@
}
}
],
"@babel/preset-react",
[
"@babel/preset-react",
{
"runtime": "automatic"
}
],
"@babel/preset-typescript"
],
"plugins": [
Expand Down
7 changes: 0 additions & 7 deletions .eslintrc.json

This file was deleted.

164 changes: 164 additions & 0 deletions eslint.config.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,164 @@
import ts from '@typescript-eslint/eslint-plugin'
import tsParser from '@typescript-eslint/parser'
import prettier from 'eslint-config-prettier'
import react from 'eslint-plugin-react'
import reactHooks from 'eslint-plugin-react-hooks'
import testingLibrary from 'eslint-plugin-testing-library'
import jest from 'eslint-plugin-jest'
import globals from 'globals'

export default [
'eslint:recommended',
// Ignored dirs
{
ignores: ['dist/**/*', 'compiled/**/*', 'bundle/**/*']
},
// Temporary ignored dirs - TODO: remove on rewrite
{
ignores: ['main/signers/**/*']
},
// All files
{
files: ['**/*.{js,mjs,ts,tsx}'],
languageOptions: {
ecmaVersion: 'latest',
globals: {
...globals.es2021
}
},
rules: {
'no-unused-vars': [
'error',
{
args: 'after-used',
ignoreRestSiblings: true,
argsIgnorePattern: '^_',
destructuredArrayIgnorePattern: '^_'
}
]
}
},
// Main process files and scripts
{
files: ['**/*.{js,mjs,ts}'],
ignores: ['app/**/*', 'resources/Components/**/*'],
languageOptions: {
globals: {
...globals.node
}
}
},
// Renderer process files
{
files: [
'app/**/*.js',
'main/dapps/server/inject/*.js',
'resources/**/*.{js,ts,tsx}',
'test/app/**/*.js',
'test/resources/Components/**/*.js'
],
languageOptions: {
globals: {
...globals.browser,
process: true,
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

do we want process to be available globally in all browser type files? seems like this might be a good case for one-of exceptions in individual files if we have any

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think it's available everywhere in the renderer process though
https://www.electronjs.org/docs/latest/api/process#sandbox

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this isn't a global, it's Electron's process object which gets imported from the Electron library like import { process } from 'electron'

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I was sure that some renderer files have a global, anyway I'll try the exception route and put what I find here

Copy link
Contributor Author

@goosewobbler goosewobbler Mar 8, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ok, here are the renderer files where we're accessing a global process:

if (process.env.NODE_ENV !== 'development') {

if (process.env.NODE_ENV !== 'development') {

if (process.env.NODE_ENV !== 'development') {

if (process.env.NODE_ENV !== 'development') {

Entry points basically - I'll add an entry for these as the global isn't available any further up.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

we must be doing something to inject this value somewhere, though I'm not sure where. when I try to print process.env to the console it shows undefined, but process.env.NODE_ENV shows "development". are we somehow mapping this?

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

global: true
}
}
},
// TS files
{
files: ['**/*.{ts,tsx}'],
languageOptions: {
parser: tsParser,
parserOptions: {
ecmaFeatures: { modules: true },
ecmaVersion: 'latest',
project: './tsconfig.json'
}
},
plugins: {
'@typescript-eslint': ts
},
rules: {
...ts.configs['eslint-recommended'].rules,
...ts.configs.recommended.rules,
'no-undef': 'off', // redundant - TS will fail to compile with undefined vars
'@typescript-eslint/no-unused-vars': [
'error',
{
args: 'after-used',
ignoreRestSiblings: true,
argsIgnorePattern: '^_',
destructuredArrayIgnorePattern: '^_'
}
],
'@typescript-eslint/no-empty-function': ['error', { allow: ['arrowFunctions'] }], // allow noop arrow functions, e.g. in a method signature for ensuring a parameter defaults to a function
'@typescript-eslint/prefer-namespace-keyword': 'off', // use ES module syntax instead of namespace
'@typescript-eslint/no-namespace': ['error', { allowDeclarations: true }]
}
},
// React / JSX files
// TODO: simplify as '**/*.{jsx,tsx}'
{
files: [
'app/**/*.js',
'resources/Components/**/*.js',
'resources/Native/**/*.js',
'resources/svg/index.js',
'test/app/**/*.js',
'test/resources/Components/**/*.js',
'test/resources/Hooks/**/*.js',
'test/jest.svg.js'
],
plugins: {
react,
'react-hooks': reactHooks
},
languageOptions: {
parserOptions: {
ecmaFeatures: {
jsx: true
}
}
},
settings: {
react: {
version: 'detect'
}
},
rules: {
...react.configs.recommended.rules,
...react.configs['jsx-runtime'].rules,
...reactHooks.configs.recommended.rules,
'react/prop-types': 'off' // all type checking to be done in TS
}
},
// Test files
{
files: ['test/**/*.js', '**/__mocks__/**/*.js'],
plugins: {
jest
},
languageOptions: {
globals: {
...globals.jest
}
}
// TODO: enable jest rules
// rules: {
// ...jest.configs.recommended.rules
// }
},
// Components test files
{
files: ['test/app/**/*.js', 'test/resources/Components/**/*.js', 'app/**/__mocks__/**/*.js'],
plugins: {
'testing-library': testingLibrary
},
rules: {
...testingLibrary.configs.react.rules
}
},
// ensure all rules work with prettier
prettier
]
Loading