Skip to content

Commit

Permalink
chore: better typechecks and eslint
Browse files Browse the repository at this point in the history
* a whole lot of configuration for eslint and tsc
* rollup & eslint upgrade
* promise rejection is now Error
  • Loading branch information
daniele-pelagatti authored Nov 19, 2023
1 parent b2fa558 commit bc894c6
Show file tree
Hide file tree
Showing 21 changed files with 681 additions and 322 deletions.
88 changes: 4 additions & 84 deletions .eslintrc.cjs
Original file line number Diff line number Diff line change
@@ -1,110 +1,30 @@
/** @type {import('eslint').ESLint.ConfigData} */
module.exports = {
// https://eslint.org/docs/user-guide/configuring#configuration-cascading-and-hierarchy
// This option interrupts the configuration hierarchy at this file
// Remove this if you have an higher level ESLint config file (it usually happens into a monorepos)
root: true,

parser: '@typescript-eslint/parser',
parserOptions: {
project: true,
tsconfigRootDir: __dirname,
extraFileExtensions: ['.html']
},
env: {
browser: true,
es2021: true,
node: true
},
parser: '@typescript-eslint/parser',

// Rules order is important, please avoid shuffling them
extends: [
// Base ESLint recommended rules
// 'eslint:recommended',

// https://github.com/typescript-eslint/typescript-eslint/tree/master/packages/eslint-plugin#usage
// ESLint typescript rules
'plugin:@typescript-eslint/recommended',
'plugin:@typescript-eslint/recommended-type-checked',
'standard'

],

plugins: [
// required to apply rules which need type information
'@typescript-eslint',
// 'html', // TODO: enable this to check examples, but with less rules :)
'jest-extended',
'simple-import-sort', // https://github.com/lydell/eslint-plugin-simple-import-sort/
'unused-imports' // https://github.com/sweepline/eslint-plugin-unused-imports

],

globals: {
ga: 'readonly', // Google Analytics
cordova: 'readonly',
__statics: 'readonly',
__QUASAR_SSR__: 'readonly',
__QUASAR_SSR_SERVER__: 'readonly',
__QUASAR_SSR_CLIENT__: 'readonly',
__QUASAR_SSR_PWA__: 'readonly',
process: 'readonly',
Capacitor: 'readonly',
chrome: 'readonly',
electron: 'readonly'
},

// add your custom rules here
rules: {
"@typescript-eslint/no-misused-promises": [
"error",
{
"checksVoidReturn": false
}
],
"@typescript-eslint/no-duplicate-type-constituents": "off",
// https://github.com/lydell/eslint-plugin-simple-import-sort/#usage
'simple-import-sort/imports': 'error',
'simple-import-sort/exports': 'error',
// https://github.com/sweepline/eslint-plugin-unused-imports
'no-unused-vars': 'off', // or "@typescript-eslint/no-unused-vars": "off",
'@typescript-eslint/no-unused-vars': 'off',
'unused-imports/no-unused-imports': 'error',
'unused-imports/no-unused-vars': ['error', { vars: 'all', args: 'none' }],

// allow async-await
'generator-star-spacing': 'off',
// allow paren-less arrow functions
'arrow-parens': 'off',
'one-var': 'off',
'no-void': 'off',
'multiline-ternary': 'off',

'import/first': 'off',
'import/namespace': 'off',
'import/default': 'error',
'import/export': 'error',
'import/extensions': 'off',
'import/no-unresolved': 'off',
'import/no-extraneous-dependencies': 'off',

// The core 'import/named' rules
// does not work with type definitions
'import/named': 'off',

'prefer-promise-reject-errors': 'off',

quotes: ['warn', 'single', { avoidEscape: true }],

// this rule, if on, would require explicit return type on the `render` function
'@typescript-eslint/explicit-function-return-type': 'off',

// in plain CommonJS modules, you can't use `import foo = require('foo')` to pass this rule, so it has to be disabled
'@typescript-eslint/no-var-requires': 'off',

// The core 'no-unused-vars' rules (in the eslint:recommended ruleset)
// does not work with type definitions
'no-unused-vars': 'off',

// allow debugger during development only
'no-debugger': process.env.NODE_ENV === 'production' ? 'error' : 'off'
'unused-imports/no-unused-vars': ['warn', { vars: 'all', varsIgnorePattern: '^_', args: 'after-used', argsIgnorePattern: '^_' }]
}
}
39 changes: 39 additions & 0 deletions examples/.eslintrc.cjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
/** @type {import('eslint').ESLint.ConfigData} */
module.exports = {
root: true,
parser: '@typescript-eslint/parser',
parserOptions: {
project: true,
tsconfigRootDir: __dirname
},
env: {
browser: true,
es2018: true
},

extends: [
'plugin:@typescript-eslint/recommended',
'plugin:@typescript-eslint/recommended-type-checked',
'plugin:compat/recommended',
'standard'
],

plugins: [
'@typescript-eslint',
'simple-import-sort',
'unused-imports'
],

rules: {
'@typescript-eslint/no-misused-promises': ['error', { checksVoidReturn: false }],
'@typescript-eslint/no-duplicate-type-constituents': 'off',
// https://github.com/lydell/eslint-plugin-simple-import-sort/#usage
'simple-import-sort/imports': 'error',
'simple-import-sort/exports': 'error',
// https://github.com/sweepline/eslint-plugin-unused-imports
'no-unused-vars': 'off',
'@typescript-eslint/no-unused-vars': 'off',
'unused-imports/no-unused-imports': 'error',
'unused-imports/no-unused-vars': ['warn', { vars: 'all', varsIgnorePattern: '^_', args: 'after-used', argsIgnorePattern: '^_' }]
}
}
1 change: 0 additions & 1 deletion examples/decode-from-jpeg.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
/* eslint-disable unused-imports/no-unused-vars */

import { decode, extractGainmapFromJPEG } from '@monogrid/gainmap-js'
import {
ClampToEdgeWrapping,
Expand Down
63 changes: 63 additions & 0 deletions examples/integrated/.eslintrc.cjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
/** @type {import('eslint').ESLint.ConfigData} */
module.exports = {
root: true,
env: {
browser: true,
node: true,
es2018: true
},
parserOptions: {
ecmaVersion: 2018,
sourceType: 'module'
},
extends: [
'mdcs',
'plugin:compat/recommended',
'plugin:@typescript-eslint/recommended'
],
plugins: [
'html',
'import'
],
settings: {
polyfills: [
'WebGL2RenderingContext'
]
},
globals: {
__THREE_DEVTOOLS__: 'readonly',
potpack: 'readonly',
fflate: 'readonly',
Stats: 'readonly',
XRWebGLBinding: 'readonly',
XRWebGLLayer: 'readonly',
GPUShaderStage: 'readonly',
GPUBufferUsage: 'readonly',
GPUTextureUsage: 'readonly',
GPUTexture: 'readonly',
GPUMapMode: 'readonly',
QUnit: 'readonly',
Ammo: 'readonly',
XRRigidTransform: 'readonly',
XRMediaBinding: 'readonly',
CodeMirror: 'readonly',
esprima: 'readonly',
jsonlint: 'readonly'
},
rules: {
'no-throw-literal': [
'error'
],
quotes: [
'error',
'single'
],
'prefer-const': [
'error',
{
destructuring: 'any',
ignoreReadBeforeAssign: false
}
]
}
};
1 change: 0 additions & 1 deletion examples/integrated/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,6 @@

<script type="module">
// @ts-check

import * as THREE from 'three';

import Stats from 'three/addons/libs/stats.module.js';
Expand Down
Loading

0 comments on commit bc894c6

Please sign in to comment.