2023-10-25 10:40:37 -05:00
|
|
|
// eslint-disable-next-line @typescript-eslint/no-var-requires
|
2023-09-12 12:52:22 -05:00
|
|
|
const { builtinModules } = require('module');
|
2023-09-12 12:50:06 -05:00
|
|
|
|
2023-10-25 10:40:37 -05:00
|
|
|
/** @type {import("@types/eslint").Linter.Config} */
|
2021-03-16 13:37:45 -05:00
|
|
|
module.exports = {
|
2023-07-03 07:59:43 -05:00
|
|
|
extends: [
|
|
|
|
'plugin:@typescript-eslint/recommended-type-checked',
|
|
|
|
'plugin:@typescript-eslint/stylistic-type-checked',
|
|
|
|
'prettier',
|
|
|
|
],
|
2021-03-16 13:37:45 -05:00
|
|
|
parser: '@typescript-eslint/parser',
|
2023-07-03 07:59:43 -05:00
|
|
|
parserOptions: {
|
|
|
|
project: ['./packages/*/tsconfig.json', './tsconfig.eslint.json'],
|
|
|
|
tsconfigRootDir: __dirname,
|
|
|
|
},
|
2022-06-22 10:59:49 -05:00
|
|
|
plugins: ['@typescript-eslint', 'prettier', 'no-only-tests'],
|
2021-03-16 13:37:45 -05:00
|
|
|
rules: {
|
2023-07-03 07:59:43 -05:00
|
|
|
// These off/configured-differently-by-default rules fit well for us
|
2024-01-30 03:35:08 -05:00
|
|
|
'@typescript-eslint/switch-exhaustiveness-check': 'error',
|
2023-07-03 07:59:43 -05:00
|
|
|
'@typescript-eslint/array-type': ['error', { default: 'array-simple' }],
|
2023-09-05 13:03:21 -05:00
|
|
|
'@typescript-eslint/no-unused-vars': [
|
2023-10-19 13:09:55 -05:00
|
|
|
'warn',
|
2023-10-25 07:21:38 -05:00
|
|
|
{
|
|
|
|
argsIgnorePattern: '^_',
|
|
|
|
varsIgnorePattern: '^_',
|
|
|
|
caughtErrorsIgnorePattern: '^_',
|
|
|
|
ignoreRestSiblings: true,
|
|
|
|
},
|
2023-09-05 13:03:21 -05:00
|
|
|
],
|
2023-07-03 07:59:43 -05:00
|
|
|
'no-only-tests/no-only-tests': 'error',
|
|
|
|
'@typescript-eslint/no-shadow': ['error'],
|
|
|
|
'no-console': 'warn',
|
|
|
|
|
|
|
|
// Todo: do we want these?
|
|
|
|
'@typescript-eslint/array-type': 'off',
|
2021-04-21 11:14:44 -05:00
|
|
|
'@typescript-eslint/ban-ts-comment': 'off',
|
2023-07-03 07:59:43 -05:00
|
|
|
'@typescript-eslint/class-literal-property-style': 'off',
|
|
|
|
'@typescript-eslint/consistent-indexed-object-style': 'off',
|
|
|
|
'@typescript-eslint/consistent-type-definitions': 'off',
|
|
|
|
'@typescript-eslint/dot-notation': 'off',
|
|
|
|
'@typescript-eslint/no-base-to-string': 'off',
|
2021-04-01 11:25:28 -05:00
|
|
|
'@typescript-eslint/no-empty-function': 'off',
|
2023-07-03 07:59:43 -05:00
|
|
|
'@typescript-eslint/no-floating-promises': 'off',
|
|
|
|
'@typescript-eslint/no-misused-promises': 'off',
|
|
|
|
'@typescript-eslint/no-redundant-type-constituents': 'off',
|
2022-01-06 16:32:24 -05:00
|
|
|
'@typescript-eslint/no-this-alias': 'off',
|
2023-07-03 07:59:43 -05:00
|
|
|
'@typescript-eslint/no-unsafe-argument': 'off',
|
|
|
|
'@typescript-eslint/no-unsafe-assignment': 'off',
|
|
|
|
'@typescript-eslint/no-unsafe-call': 'off',
|
|
|
|
'@typescript-eslint/no-unsafe-member-access': 'off',
|
|
|
|
'@typescript-eslint/no-unsafe-return': 'off',
|
|
|
|
'@typescript-eslint/prefer-nullish-coalescing': 'off',
|
2023-07-12 02:11:46 -05:00
|
|
|
'@typescript-eslint/prefer-optional-chain': 'off',
|
2023-07-03 07:59:43 -05:00
|
|
|
'@typescript-eslint/prefer-string-starts-ends-with': 'off',
|
|
|
|
'@typescript-eslint/require-await': 'off',
|
|
|
|
'@typescript-eslint/restrict-plus-operands': 'off',
|
|
|
|
'@typescript-eslint/restrict-template-expressions': 'off',
|
|
|
|
'@typescript-eslint/sort-type-constituents': 'off',
|
|
|
|
'@typescript-eslint/unbound-method': 'off',
|
2023-07-12 02:14:48 -05:00
|
|
|
'@typescript-eslint/no-explicit-any': 'off',
|
2023-07-03 07:59:43 -05:00
|
|
|
|
2023-12-04 11:56:32 -05:00
|
|
|
// Enforce separate type imports for type-only imports to avoid bundling unneeded code
|
|
|
|
'@typescript-eslint/consistent-type-imports': [
|
|
|
|
'error',
|
|
|
|
{
|
|
|
|
prefer: 'type-imports',
|
|
|
|
fixStyle: 'separate-type-imports',
|
|
|
|
disallowTypeAnnotations: false,
|
|
|
|
},
|
|
|
|
],
|
|
|
|
|
2023-07-03 07:59:43 -05:00
|
|
|
// These rules enabled by the preset configs don't work well for us
|
|
|
|
'@typescript-eslint/await-thenable': 'off',
|
2021-03-16 13:37:45 -05:00
|
|
|
'prefer-const': 'off',
|
|
|
|
},
|
2022-08-23 14:55:03 -05:00
|
|
|
overrides: [
|
2023-09-12 12:52:22 -05:00
|
|
|
{
|
2023-09-12 12:50:06 -05:00
|
|
|
// Ensure Node builtins aren't included in Astro's server runtime
|
|
|
|
files: ['packages/astro/src/runtime/**/*.ts'],
|
|
|
|
rules: {
|
2023-09-12 12:52:22 -05:00
|
|
|
'no-restricted-imports': [
|
|
|
|
'error',
|
|
|
|
{
|
|
|
|
paths: [...builtinModules],
|
|
|
|
patterns: ['node:*'],
|
|
|
|
},
|
|
|
|
],
|
|
|
|
},
|
2023-09-12 12:50:06 -05:00
|
|
|
},
|
2023-10-25 10:40:37 -05:00
|
|
|
{
|
|
|
|
files: ['packages/astro/src/runtime/client/**/*.ts'],
|
|
|
|
env: {
|
|
|
|
browser: true,
|
|
|
|
},
|
|
|
|
},
|
2022-08-23 14:55:03 -05:00
|
|
|
{
|
2022-09-13 16:23:59 -05:00
|
|
|
files: ['packages/**/test/*.js', 'packages/**/*.js'],
|
2022-08-23 14:55:03 -05:00
|
|
|
env: {
|
|
|
|
mocha: true,
|
|
|
|
},
|
|
|
|
globals: {
|
|
|
|
globalThis: false, // false means read-only
|
|
|
|
},
|
|
|
|
rules: {
|
|
|
|
'no-console': 'off',
|
|
|
|
},
|
|
|
|
},
|
2022-10-03 10:37:21 -05:00
|
|
|
{
|
|
|
|
files: ['packages/integrations/**/*.ts'],
|
|
|
|
rules: {
|
|
|
|
'no-console': ['error', { allow: ['warn', 'error', 'info', 'debug'] }],
|
|
|
|
},
|
|
|
|
},
|
2023-03-01 03:46:06 -05:00
|
|
|
{
|
|
|
|
files: ['benchmark/**/*.js'],
|
|
|
|
rules: {
|
2023-07-03 07:59:43 -05:00
|
|
|
'@typescript-eslint/no-unused-vars': 'off',
|
2023-03-01 03:46:06 -05:00
|
|
|
'no-console': 'off',
|
|
|
|
},
|
|
|
|
},
|
2024-01-09 15:56:28 -05:00
|
|
|
{
|
|
|
|
files: ['packages/astro/src/core/errors/errors-data.ts'],
|
|
|
|
rules: {
|
|
|
|
// This file is used for docs generation, as such the code need to be in a certain format, we can somewhat ensure this with these rules
|
|
|
|
'object-shorthand': ['error', 'methods', { avoidExplicitReturnArrows: true }],
|
|
|
|
'arrow-body-style': ['error', 'never'],
|
|
|
|
},
|
|
|
|
},
|
2022-08-23 14:55:03 -05:00
|
|
|
],
|
2021-03-16 13:37:45 -05:00
|
|
|
};
|