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

feat(dev-tools): eslint default config clean up #466

Merged
merged 1 commit into from
May 6, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 0 additions & 10 deletions .eslintrc.cjs
Original file line number Diff line number Diff line change
@@ -1,21 +1,11 @@
const {getESLintConfig} = require('ocular-dev-tools/configuration');

module.exports = getESLintConfig({
react: '16.8.2',
overrides: {
parserOptions: {
project: ['./tsconfig.json']
},

settings: {
// Ensure eslint finds typescript files
'import/resolver': {
node: {
extensions: ['.js', '.jsx', '.mjs', '.ts', '.tsx']
}
}
},

rules: {
'import/no-extraneous-dependencies': 0,
'import/no-unresolved': 0,
Expand Down
8 changes: 0 additions & 8 deletions babel.config.cjs

This file was deleted.

7 changes: 3 additions & 4 deletions modules/dev-tools/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -76,16 +76,14 @@
"@esbuild-plugins/node-globals-polyfill": "^0.2.0",
"@esbuild-plugins/node-modules-polyfill": "^0.2.0",
"@probe.gl/test-utils": "^4.0.6",
"@typescript-eslint/eslint-plugin": "^6.14.0",
"@typescript-eslint/parser": "^6.14.0",
"babel-plugin-version-inline": "^1.0.0",
"c8": "^7.12.0",
"coveralls": "^3.0.3",
"deepmerge": "^4.2.2",
"esbuild": "^0.16.7",
"esbuild-plugin-external-global": "^1.0.1",
"eslint": "^8.52.0",
"eslint-config-prettier": "^6.7.0",
"eslint-config-prettier": "^8.0.0",
"eslint-plugin-babel": "^5.3.1",
"eslint-plugin-import": "^2.28.0",
"eslint-plugin-jsx-a11y": "^6.1.2",
Expand All @@ -95,12 +93,13 @@
"glob": "^7.1.4",
"lerna": "^8.1.0",
"minimatch": "^3.0.0",
"prettier": "3.0.3",
"prettier": "^3.2.0",
"prettier-check": "2.0.0",
"tape": "^4.11.0",
"tape-promise": "^4.0.0",
"tap-spec": "^5.0.0",
"typescript": "^5.2.2",
"typescript-eslint": "^7.7.0",
"ts-node": "~10.9.0",
"ts-patch": "^3.1.2",
"tsconfig-paths": "^4.1.1",
Expand Down
30 changes: 17 additions & 13 deletions modules/dev-tools/scripts/bundle.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,19 +17,23 @@ for (let i = 1; i < process.argv.length; i++) {
}
}

const buildConfig = await getBundleConfig({
...env,
input: entryPoint
});
run();

if (env.watch) {
buildConfig.watch = true;
await esbuild.build(buildConfig);
/* eslint-disable no-console */
console.log('watching...');
} else {
const result = await esbuild.build(buildConfig);
if (result.errors.length > 0) {
process.exit(1);
async function run() {
const buildConfig = await getBundleConfig({
...env,
input: entryPoint
});

if (env.watch) {
buildConfig.watch = true;
await esbuild.build(buildConfig);
/* eslint-disable no-console */
console.log('watching...');
} else {
const result = await esbuild.build(buildConfig);
if (result.errors.length > 0) {
process.exit(1);
}
}
}
132 changes: 52 additions & 80 deletions modules/dev-tools/src/configuration/get-eslint-config.ts
Original file line number Diff line number Diff line change
@@ -1,37 +1,36 @@
import eslint from '@typescript-eslint/eslint-plugin';
import deepMerge from 'deepmerge';
import {getValidPath, ocularRoot} from '../utils/utils.js';
import {inspect} from 'util';
import {resolve} from 'path';

const typescriptConfigs = eslint.configs;
const localRules = (path) => resolve(ocularRoot, 'src/configuration', path);

const DEFAULT_OPTIONS = {
react: false
} as const;

const babelConfig = getValidPath(
'./.babelrc',
'./.babelrc.js',
'./.babelrc.cjs',
'./babel.config.js',
'./babel.config.cjs'
);

const DEFAULT_CONFIG = {
extends: [
localRules('./eslint-config-uber-es2015/eslintrc.json'),
'prettier',
'prettier/react',
'plugin:import/errors'
'plugin:import/recommended'
],
plugins: ['import'],
parser: '@babel/eslint-parser',
parser: babelConfig ? '@babel/eslint-parser' : '',
parserOptions: {
ecmaVersion: 2020,
// @babel/eslint-parser issues https://github.com/babel/babel/issues/11975
requireConfigFile: false,
babelOptions: {
configFile: getValidPath(
'./.babelrc',
'./.babelrc.js',
'./.babelrc.cjs',
'./babel.config.js',
'./babel.config.cjs'
)
configFile: babelConfig
}
},
env: {
Expand All @@ -43,14 +42,14 @@ const DEFAULT_CONFIG = {
__VERSION__: 'readonly'
},
rules: {
'guard-for-in': 0,
'generator-star-spacing': 0,
'func-names': 0,
'no-inline-comments': 0,
'no-multi-str': 0,
'space-before-function-paren': 0,
'guard-for-in': 'off',
'func-names': 'off',
'no-inline-comments': 'off',
'no-multi-str': 'off',
camelcase: 'warn',
// Let prettier handle this
indent: 'off',
'accessor-pairs': ['error', {getWithoutSet: false, setWithoutGet: false}],
'import/no-unresolved': ['error'],
'import/no-extraneous-dependencies': ['error', {devDependencies: false, peerDependencies: true}]
},
settings: {
Expand All @@ -72,72 +71,46 @@ const DEFAULT_CONFIG = {
sourceType: 'module', // we want to use ES modules
project: './tsconfig.json'
},
extends: ['plugin:@typescript-eslint/recommended-type-checked'],
plugins: ['@typescript-eslint'],
rules: {
...typescriptConfigs['eslint-recommended'].rules,
...typescriptConfigs.recommended.rules,
...typescriptConfigs['recommended-requiring-type-checking'].rules,

// typescript-eslint 6.0
'@typescript-eslint/no-unsafe-argument': 0,
'@typescript-eslint/no-redundant-type-constituents': 0,
'@typescript-eslint/no-unsafe-enum-comparison': 1,
'@typescript-eslint/no-duplicate-type-constituents': 1,
'@typescript-eslint/no-base-to-string': 1,
'@typescript-eslint/no-loss-of-precision': 1,

// We still have some issues with import resolution
'import/named': 0,
'import/no-extraneous-dependencies': ['warn'],
// Warn instead of error
'max-params': ['warn'],
'no-undef': ['warn'],
camelcase: ['warn'],
indent: ['warn', 2, {SwitchCase: 1}],
quotes: ['warn', 'single'],
'no-process-env': 'off',

// typescript rules

// Some of JS rules don't always work correctly in TS and
// hence need to be reimported as TS rules
'no-redeclare': 'off',
'no-shadow': 'off',
'no-use-before-define': 'off',
'no-dupe-class-members': 'off',

// TODO - These rules are sometimes not found?
// '@typescript-eslint/no-shadow': ['warn'],
// '@typescript-eslint/no-redeclare': ['warn'],
'@typescript-eslint/no-dupe-class-members': 'error',
'@typescript-eslint/switch-exhaustiveness-check': 'error',

// Rules disabled because they conflict with our preferred style
// We use function hoisting to put exports at top of file
'@typescript-eslint/no-use-before-define': 'off',
'@typescript-eslint/no-dupe-class-members': ['error'],

// We encourage explicit typing, e.g `field: string = ''`
'@typescript-eslint/no-inferrable-types': 'off',

'@typescript-eslint/no-empty-interface': ['warn'],
'@typescript-eslint/restrict-template-expressions': ['warn'],
'@typescript-eslint/explicit-module-boundary-types': ['warn'],
'@typescript-eslint/require-await': ['warn'],
'@typescript-eslint/no-unsafe-return': ['warn'],
'@typescript-eslint/no-unsafe-call': ['warn'],

// some day we will hopefully be able to enable this rule
'@typescript-eslint/no-explicit-any': 'off',
'@typescript-eslint/ban-ts-comment': ['warn'],
'@typescript-eslint/ban-types': ['warn'],
'@typescript-eslint/no-unsafe-member-access': ['warn'],
'@typescript-eslint/no-unsafe-assignment': ['warn'],
'@typescript-eslint/no-var-requires': ['warn'],
'@typescript-eslint/no-unused-vars': ['warn'],
'@typescript-eslint/switch-exhaustiveness-check': ['error'],
'@typescript-eslint/no-floating-promises': ['warn'],
'@typescript-eslint/await-thenable': ['warn'],
'@typescript-eslint/no-misused-promises': ['warn'],
'@typescript-eslint/restrict-plus-operands': ['warn'],
'@typescript-eslint/no-empty-function': ['warn']
// Allow noOp as default value for callbacks
'@typescript-eslint/no-empty-function': 'off',

// Rules downgraded because they are deemed acceptable
'@typescript-eslint/ban-ts-comment': [
'error',
{
'ts-expect-error': 'allow-with-description',
'ts-ignore': 'allow-with-description',
'ts-nocheck': 'allow-with-description',
'ts-check': false,
minimumDescriptionLength: 3
}
],
'@typescript-eslint/no-floating-promises': 'warn',
'@typescript-eslint/restrict-template-expressions': 'warn',
'@typescript-eslint/no-empty-interface': 'warn',
'@typescript-eslint/require-await': 'warn',

// Rules that restrict the use of `any`
// Might be too strict for our code base, but should be gradually enabled
'@typescript-eslint/no-explicit-any': 'warn',
'@typescript-eslint/no-unsafe-argument': 'warn',
'@typescript-eslint/no-unsafe-assignment': 'warn',
'@typescript-eslint/no-unsafe-call': 'warn',
'@typescript-eslint/no-unsafe-enum-comparison': 'warn',
'@typescript-eslint/no-unsafe-member-access': 'warn',
'@typescript-eslint/no-unsafe-return': 'warn',
'@typescript-eslint/explicit-module-boundary-types': 'warn'
}
},
{
Expand All @@ -162,8 +135,7 @@ function getReactConfig(options) {
extends: [
localRules('./eslint-config-uber-jsx/eslintrc.json'),
'prettier',
'prettier/react',
'plugin:import/errors'
'plugin:import/recommended'
],
plugins: ['import', 'react'],
settings: {
Expand Down
2 changes: 1 addition & 1 deletion modules/dev-tools/src/helpers/esm-alias.ts
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ export const resolve: ResolveHook = (specifier, context, nextResolver) => {
specifier = `${pathToFileURL(mappedSpecifier)}`;
}
}
// @ts-ignore
// @ts-expect-error omitted arguments are populated by Node.js
return nextResolver(specifier);
};

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
]
}
*/
import type {Program, TransformationContext, SourceFile, Node, StringLiteral} from 'typescript';
import type {Program, TransformationContext, SourceFile, Node} from 'typescript';
import type {TransformerExtras, PluginConfig} from 'ts-patch';
import {GL} from '@luma.gl/constants';

Expand Down
Loading
Loading