2023-03-15 06:42:14 +03:00
|
|
|
/** @file ESLint configuration file. */
|
2024-10-21 15:56:39 +03:00
|
|
|
/**
|
|
|
|
* NOTE: The "Experimental: Use Flat Config" option must be enabled.
|
|
|
|
* Flat config is still not quite mature, so is disabled by default.
|
|
|
|
*/
|
2023-03-15 06:42:14 +03:00
|
|
|
import * as path from 'node:path'
|
|
|
|
import * as url from 'node:url'
|
|
|
|
|
2023-06-19 02:02:08 +03:00
|
|
|
// The preferred syntax is `import * as name`, however these modules do not support it.
|
2023-03-15 06:42:14 +03:00
|
|
|
// This is specialcased in other files, but these modules shouldn't be used in other files anyway.
|
2024-10-28 15:58:41 +03:00
|
|
|
|
2023-03-15 06:42:14 +03:00
|
|
|
import eslintJs from '@eslint/js'
|
2024-07-24 11:47:05 +03:00
|
|
|
import tsEslint from '@typescript-eslint/eslint-plugin'
|
2024-10-11 21:23:02 +03:00
|
|
|
import vueTsEslintConfig from '@vue/eslint-config-typescript'
|
2023-03-15 06:42:14 +03:00
|
|
|
import jsdoc from 'eslint-plugin-jsdoc'
|
2023-07-06 14:52:32 +03:00
|
|
|
import react from 'eslint-plugin-react'
|
2024-10-28 15:58:41 +03:00
|
|
|
import reactCompiler from 'eslint-plugin-react-compiler'
|
2023-07-06 14:52:32 +03:00
|
|
|
import reactHooks from 'eslint-plugin-react-hooks'
|
2024-10-11 21:23:02 +03:00
|
|
|
import pluginVue from 'eslint-plugin-vue'
|
2024-07-24 11:47:05 +03:00
|
|
|
import globals from 'globals'
|
2023-03-15 06:42:14 +03:00
|
|
|
|
2023-05-19 22:55:29 +03:00
|
|
|
// =================
|
|
|
|
// === Constants ===
|
|
|
|
// =================
|
|
|
|
|
Fix various issues on the Dashboard (#10256)
- Fix React DevTools not working in Firefox
- Fix selection of asset names when editing them, not working at all in Firefox
- Convert tick/cross buttons when editing assets, and the "plus" and "reload" buttons on the "shared with" column, "labels" column, and keyboard shortcuts table, to match more with the rest of the design
- Update clip path when the container resizes, so that the icons for hidden columns never overlap the actual table header
- Fix #10184
- Fix renames being committed even when cancelling
- Fix duplicate name detection - previously, all asset types only checked folders with the same name, not assets with the same name
- I'm not 100% sure this is the correct behavior still
- Stop using `kbd` (`aria.Keyboard`) to display keyboard shortcuts, since they should not be displayed in a monospace font.
- Fix "plus" and "reload" buttons going past the right side of their parent table cell
- Limit length of `PermissionDisplay` - if the username of a user with permission is too long, it uses a tooltip instead
- Update the username dynamically for all permissions owned by self, when changing username in the settings.
- This avoids having to fully invalidate the directory tree every time the username changes, given that nothing changes about the assets' metadata themselves.
- Cache children in the Drive tree
- This avoids loading spinners when closing a folder and immediately reopening it.
- Note that children are still re-fetched on reopen to ensure freshness
# Important Notes
- This MAY be split into multiple smaller PRs. However, I think it's better to QA as a single PR, to avoid duplicating work checking behavior that may be changed by a sibling PR (assuming the PR was split into multiple).
2024-06-20 21:30:24 +03:00
|
|
|
const DEBUG_STATEMENTS_MESSAGE = 'Avoid leaving debugging statements when committing code'
|
2023-03-15 06:42:14 +03:00
|
|
|
const DIR_NAME = path.dirname(url.fileURLToPath(import.meta.url))
|
|
|
|
const NAME = 'enso'
|
2024-10-21 15:56:39 +03:00
|
|
|
/**
|
|
|
|
* An explicit whitelist of CommonJS modules, which do not support namespace imports.
|
2023-03-15 06:42:14 +03:00
|
|
|
* Many of these have incorrect types, so no type error may not mean they support ESM,
|
|
|
|
* and conversely type errors may not mean they don't support ESM -
|
|
|
|
* but we add those to the whitelist anyway otherwise we get type errors.
|
2023-03-15 14:54:16 +03:00
|
|
|
* In particular, `string-length` supports ESM but its type definitions don't.
|
2023-07-26 15:59:48 +03:00
|
|
|
* `yargs` is a modules we explicitly want the default imports of.
|
2024-10-21 15:56:39 +03:00
|
|
|
* `node:process` is here because `process.on` does not exist on the namespace import.
|
|
|
|
*/
|
2023-03-15 14:54:16 +03:00
|
|
|
const DEFAULT_IMPORT_ONLY_MODULES =
|
2024-07-26 09:34:51 +03:00
|
|
|
'@vitejs\\u002Fplugin-react|node:process|chalk|string-length|yargs|yargs\\u002Fyargs|sharp|to-ico|connect|morgan|serve-static|tiny-invariant|clsx|create-servers|electron-is-dev|fast-glob|esbuild-plugin-.+|opener|tailwindcss.*|@modyfi\\u002Fvite-plugin-yaml|build-info|is-network-error|validator.+|.*[.]json$'
|
2023-03-15 06:42:14 +03:00
|
|
|
const RELATIVE_MODULES =
|
2024-07-26 18:14:31 +03:00
|
|
|
'projectManager|server|configParser|authentication|config|debug|detect|fileAssociations|index|ipc|log|naming|paths|preload|projectManagement|security|urlAssociations|contentConfig|desktopEnvironment|#\\u002F.*'
|
2024-02-29 13:36:47 +03:00
|
|
|
const ALLOWED_DEFAULT_IMPORT_MODULES = `${DEFAULT_IMPORT_ONLY_MODULES}|postcss|ajv\\u002Fdist\\u002F2020|${RELATIVE_MODULES}`
|
2023-03-20 12:35:16 +03:00
|
|
|
const STRING_LITERAL = ':matches(Literal[raw=/^["\']/], TemplateLiteral)'
|
2023-06-19 02:02:08 +03:00
|
|
|
const NOT_CAMEL_CASE = '/^(?!_?[a-z][a-z0-9*]*([A-Z0-9][a-z0-9]*)*$)(?!React$)/'
|
2023-07-18 14:23:41 +03:00
|
|
|
const WHITELISTED_CONSTANTS = 'logger|.+Context|interpolationFunction.+'
|
2023-03-15 06:42:14 +03:00
|
|
|
const NOT_CONSTANT_CASE = `/^(?!${WHITELISTED_CONSTANTS}$|_?[A-Z][A-Z0-9]*(_[A-Z0-9]+)*$)/`
|
2023-05-19 22:55:29 +03:00
|
|
|
|
|
|
|
// =======================================
|
|
|
|
// === Restricted syntactic constructs ===
|
|
|
|
// =======================================
|
2023-03-15 06:42:14 +03:00
|
|
|
|
|
|
|
// Extracted to a variable because it needs to be used twice:
|
|
|
|
// - once as-is for `.d.ts`
|
|
|
|
// - once explicitly disallowing `declare`s in regular `.ts`.
|
|
|
|
const RESTRICTED_SYNTAXES = [
|
2024-07-26 09:34:51 +03:00
|
|
|
{
|
|
|
|
selector: `ImportDeclaration[source.value=/^(?!(${ALLOWED_DEFAULT_IMPORT_MODULES})$)[^.]/] > ImportDefaultSpecifier`,
|
|
|
|
message:
|
|
|
|
'No default imports from modules. Add to `DEFAULT_IMPORT_ONLY_MODULES` in `eslint.config.js` if the module only has a default export.',
|
|
|
|
},
|
|
|
|
{
|
|
|
|
selector: `ImportDeclaration[source.value=/^(?:${DEFAULT_IMPORT_ONLY_MODULES})$/] > ImportNamespaceSpecifier`,
|
|
|
|
message: 'No namespace imports from modules that only have a default import',
|
|
|
|
},
|
|
|
|
{
|
|
|
|
selector: `ImportDeclaration[source.value=/\\.(?:json|yaml|yml)$/] > ImportDefaultSpecifier[local.name=${NOT_CONSTANT_CASE}]`,
|
|
|
|
message: 'Use `CONSTANT_CASE` for imports from data files',
|
|
|
|
},
|
|
|
|
{
|
|
|
|
selector: `ImportDeclaration[source.value=/\\.json$/]:not(:has(ImportAttribute[key.name=type][value.value=json]))`,
|
|
|
|
message: "JSON imports must be { type: 'json' }",
|
|
|
|
},
|
|
|
|
{
|
|
|
|
selector: `ImportDeclaration[source.value=/\\.(?:yaml|yml)$/]:not(:has(ImportAttribute[key.name=type][value.value=yaml]))`,
|
|
|
|
message: "YAML imports must be { type: 'yaml' }",
|
|
|
|
},
|
|
|
|
{
|
|
|
|
selector: `ImportDeclaration[source.value=/\\.(?:json|yaml|yml)$/] > ImportNamespaceSpecifier`,
|
|
|
|
message: 'Use default imports for imports from data files',
|
|
|
|
},
|
|
|
|
{
|
|
|
|
selector: `ImportNamespaceSpecifier > Identifier[name=${NOT_CAMEL_CASE}]`,
|
|
|
|
message: 'Use `camelCase` for imports',
|
|
|
|
},
|
|
|
|
{
|
|
|
|
selector: `:matches(ImportDefaultSpecifier[local.name=/^${NAME}/i], ImportNamespaceSpecifier > Identifier[name=/^${NAME}/i])`,
|
|
|
|
message: `Don't prefix modules with \`${NAME}\``,
|
|
|
|
},
|
|
|
|
{
|
|
|
|
selector: 'ForOfStatement > .left[kind=let]',
|
|
|
|
message: 'Use `for (const x of xs)`, not `for (let x of xs)`',
|
|
|
|
},
|
|
|
|
{
|
|
|
|
selector: 'TSTypeAliasDeclaration > :matches(TSLiteralType)',
|
|
|
|
message: 'No aliases to literal types',
|
|
|
|
},
|
|
|
|
{
|
|
|
|
selector:
|
|
|
|
'TSTypeAliasDeclaration > :matches(TSBooleanKeyword, TSBigintKeyword, TSNullKeyword, TSNumberKeyword, TSObjectKeyword, TSStringKeyword, TSSymbolKeyword, TSUndefinedKeyword, TSUnknownKeyword, TSVoidKeyword)',
|
|
|
|
message:
|
|
|
|
'No aliases to primitives - consider using brands instead: `string & { _brand: "BrandName"; }`',
|
|
|
|
},
|
|
|
|
{
|
|
|
|
// Matches non-functions.
|
|
|
|
selector: `:matches(Program, ExportNamedDeclaration, TSModuleBlock) > VariableDeclaration[kind=const] > VariableDeclarator[id.name=${NOT_CONSTANT_CASE}]:not(:matches([init.callee.object.name=React][init.callee.property.name=forwardRef], :has(ArrowFunctionExpression), :has(CallExpression[callee.object.name=newtype][callee.property.name=newtypeConstructor])))`,
|
|
|
|
message: 'Use `CONSTANT_CASE` for top-level constants that are not functions',
|
|
|
|
},
|
|
|
|
{
|
|
|
|
selector: `:matches(Program, ExportNamedDeclaration, TSModuleBlock) > VariableDeclaration > VariableDeclarator > ArrowFunctionExpression`,
|
|
|
|
message: 'Use `function foo() {}` instead of `const foo = () => {}`',
|
|
|
|
},
|
|
|
|
{
|
|
|
|
selector: `ClassBody > PropertyDefinition > ArrowFunctionExpression`,
|
|
|
|
message: 'Use `foo() {}` instead of `foo = () => {}`',
|
|
|
|
},
|
|
|
|
{
|
|
|
|
// This lint intentionally excludes classes and readonly arrays.
|
|
|
|
selector: 'TSInterfaceBody:has(TSPropertySignature[readonly=false])',
|
|
|
|
message: 'Add `readonly` modifier to all interface properties',
|
|
|
|
},
|
|
|
|
{
|
|
|
|
selector: `TSAsExpression:not(:has(TSTypeReference > Identifier[name=const]))`,
|
|
|
|
message: 'Avoid `as T`. Consider using a type annotation instead.',
|
|
|
|
},
|
|
|
|
{
|
|
|
|
selector: 'ExportNamedDeclaration > VariableDeclaration[kind=let]',
|
|
|
|
message: 'Use `export const` instead of `export let`',
|
|
|
|
},
|
|
|
|
{
|
|
|
|
selector: `Program > VariableDeclaration[kind=let] > * > ObjectExpression:has(Property > ${STRING_LITERAL}.value):not(:has(Property > .value:not(${STRING_LITERAL})))`,
|
|
|
|
message:
|
|
|
|
'Use `const` instead of `let` for top-level object literals only containing string literals',
|
|
|
|
},
|
|
|
|
{
|
|
|
|
selector:
|
|
|
|
'ImportDeclaration[source.value=/^(?:assert|async_hooks|buffer|child_process|cluster|console|constants|crypto|dgram|diagnostics_channel|dns|domain|events|fs|fs\\u002Fpromises|http|http2|https|inspector|module|net|os|path|perf_hooks|process|punycode|querystring|readline|repl|stream|string_decoder|timers|tls|trace_events|tty|url|util|v8|vm|wasi|worker_threads|zlib)$/]',
|
|
|
|
message: 'Use `node:` prefix to import builtin node modules',
|
|
|
|
},
|
|
|
|
{
|
|
|
|
selector: 'TSEnumDeclaration:not(:has(TSEnumMember))',
|
|
|
|
message: 'Enums must not be empty',
|
|
|
|
},
|
|
|
|
{
|
|
|
|
selector: 'TSAsExpression:has(TSUnknownKeyword, TSNeverKeyword, TSAnyKeyword) > TSAsExpression',
|
|
|
|
message: 'Use type assertions to specific types instead of `unknown`, `any` or `never`',
|
|
|
|
},
|
|
|
|
{
|
|
|
|
selector: ':matches(MethodDeclaration, FunctionDeclaration) FunctionDeclaration',
|
|
|
|
message: 'Use arrow functions for nested functions',
|
|
|
|
},
|
|
|
|
{
|
|
|
|
selector: 'IfStatement > ExpressionStatement',
|
|
|
|
message: 'Wrap `if` branches in `{}`',
|
|
|
|
},
|
|
|
|
{
|
|
|
|
selector: ':matches(ForStatement[test=null], ForStatement[test.value=true])',
|
|
|
|
message: 'Use `while (true)` instead of `for (;;)`',
|
|
|
|
},
|
|
|
|
{
|
|
|
|
selector: `:matches(\
|
2024-03-25 11:13:24 +03:00
|
|
|
JSXAttribute[name.name=/^(?:alt|error|label|placeholder|text|title|actionButtonLabel|actionText|aria-label)$/][value.raw=/^'|^"|^\`/], \
|
|
|
|
JSXText[value=/\\S/], \
|
|
|
|
JSXAttribute[name.name=/^(?:alt|error|label|placeholder|text|title|actionButtonLabel|actionText|aria-label)$/] ConditionalExpression:matches(\
|
|
|
|
[consequent.raw=/^'|^"|^\`/], \
|
|
|
|
[alternate.raw=/^'|^"|^\`/]\
|
|
|
|
)\
|
|
|
|
)`,
|
2024-07-26 09:34:51 +03:00
|
|
|
message: 'Use a `getText()` from `useText` instead of a literal string',
|
|
|
|
},
|
|
|
|
{
|
|
|
|
selector: `JSXAttribute[name.name=/^(?:className)$/] TemplateLiteral`,
|
|
|
|
message:
|
|
|
|
'Use `tv` from `#/utilities/tailwindVariants` or `twMerge` from `tailwind-merge` instead of template strings for classes',
|
|
|
|
},
|
|
|
|
{
|
|
|
|
selector: 'JSXOpeningElement[name.name=button] > JSXIdentifier',
|
|
|
|
message: 'Use `Button` or `UnstyledButton` instead of `button`',
|
|
|
|
},
|
|
|
|
{
|
|
|
|
selector: 'JSXOpeningElement[name.name=/^h[123456]$/] > JSXIdentifier',
|
|
|
|
message: 'Use `aria.Heading` instead of `h1`-`h6`',
|
|
|
|
},
|
2023-03-15 06:42:14 +03:00
|
|
|
]
|
|
|
|
|
2023-05-19 22:55:29 +03:00
|
|
|
// ============================
|
|
|
|
// === ESLint configuration ===
|
|
|
|
// ============================
|
|
|
|
|
2023-03-15 06:42:14 +03:00
|
|
|
export default [
|
2024-07-26 09:34:51 +03:00
|
|
|
{
|
|
|
|
// Playwright build cache and Vite build directory.
|
2024-08-22 17:09:17 +03:00
|
|
|
ignores: [
|
|
|
|
'**/.cache/**',
|
|
|
|
'**/playwright-report',
|
|
|
|
'**/dist',
|
2024-10-14 19:11:42 +03:00
|
|
|
'**/mockDist',
|
2024-08-22 17:09:17 +03:00
|
|
|
'**/build.mjs',
|
|
|
|
'**/*.timestamp-*.mjs',
|
2024-10-11 21:23:02 +03:00
|
|
|
'**/node_modules',
|
2024-10-21 15:56:39 +03:00
|
|
|
'**/generated',
|
|
|
|
'app/rust-ffi/pkg/',
|
2024-08-22 17:09:17 +03:00
|
|
|
],
|
2024-07-26 09:34:51 +03:00
|
|
|
},
|
2024-10-11 21:23:02 +03:00
|
|
|
eslintJs.configs.recommended,
|
|
|
|
...pluginVue.configs['flat/recommended'],
|
|
|
|
...vueTsEslintConfig(),
|
|
|
|
{
|
|
|
|
// files: ['{**,src}/*.{vue,js,jsx,cjs,mjs,ts,tsx,cts,mts}'],
|
|
|
|
languageOptions: {
|
|
|
|
parserOptions: {
|
|
|
|
tsconfigRootDir: DIR_NAME,
|
|
|
|
ecmaVersion: 'latest',
|
|
|
|
extraFileExtensions: ['.vue'],
|
2024-10-21 15:56:39 +03:00
|
|
|
projectService: {
|
|
|
|
allowDefaultProject: [
|
|
|
|
'app/ydoc-server/vitest.config.ts',
|
|
|
|
'app/ydoc-shared/vitest.config.ts',
|
|
|
|
],
|
|
|
|
},
|
2024-10-11 21:23:02 +03:00
|
|
|
},
|
|
|
|
},
|
|
|
|
rules: {
|
|
|
|
camelcase: ['warn', { ignoreImports: true, ignoreDestructuring: true }],
|
|
|
|
'no-inner-declarations': 'off',
|
|
|
|
'vue/attribute-hyphenation': ['error', 'never'],
|
|
|
|
'vue/v-on-event-hyphenation': ['error', 'never'],
|
|
|
|
'vue/singleline-html-element-content-newline': 'off',
|
|
|
|
'@typescript-eslint/no-unused-vars': [
|
|
|
|
'warn',
|
|
|
|
{
|
|
|
|
varsIgnorePattern: '^_',
|
|
|
|
argsIgnorePattern: '^_',
|
|
|
|
},
|
|
|
|
],
|
|
|
|
'@typescript-eslint/no-namespace': 'off',
|
2024-11-04 18:33:53 +03:00
|
|
|
// Empty interfaces have valid uses; e.g. although an empty interface extending a class is semantically equivalent
|
|
|
|
// to a type alias, it is not resolved by IDEs to the base type (which may be internal).
|
|
|
|
'@typescript-eslint/no-empty-object-type': ['error', { allowInterfaces: 'always' }],
|
2024-10-11 21:23:02 +03:00
|
|
|
'no-unused-labels': 'off',
|
|
|
|
// Taken care of by prettier
|
|
|
|
'vue/max-attributes-per-line': 'off',
|
|
|
|
'vue/html-indent': 'off',
|
|
|
|
'vue/html-closing-bracket-newline': 'off',
|
|
|
|
|
|
|
|
// TODO[ao]; off temporarily
|
|
|
|
'@typescript-eslint/no-explicit-any': 'off',
|
|
|
|
'vue/html-self-closing': 'off',
|
|
|
|
},
|
|
|
|
},
|
|
|
|
{
|
|
|
|
files: ['app/gui/templates/*.vue'],
|
|
|
|
rules: {
|
|
|
|
'vue/multi-word-component-names': 0,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
// JsDoc lints for typescript - the recommended set with some modifications.
|
|
|
|
{
|
|
|
|
ignores: ['**/*.js'],
|
|
|
|
...jsdoc.configs['flat/recommended-typescript'],
|
|
|
|
rules: {
|
|
|
|
...jsdoc.configs['flat/recommended-typescript'].rules,
|
|
|
|
'jsdoc/check-param-names': [
|
|
|
|
'warn',
|
|
|
|
{ checkDestructured: false, disableMissingParamChecks: true },
|
|
|
|
],
|
|
|
|
'jsdoc/require-jsdoc': [
|
|
|
|
'warn',
|
|
|
|
{
|
|
|
|
publicOnly: true,
|
|
|
|
require: {
|
|
|
|
FunctionDeclaration: true,
|
|
|
|
MethodDefinition: true,
|
|
|
|
ClassDeclaration: true,
|
|
|
|
ArrowFunctionExpression: false,
|
|
|
|
FunctionExpression: true,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
],
|
|
|
|
'jsdoc/require-param': 'off',
|
|
|
|
'jsdoc/require-returns': 'off',
|
|
|
|
'jsdoc/require-yields': 'off',
|
|
|
|
},
|
|
|
|
},
|
|
|
|
|
|
|
|
// === Dashboard Rules ===
|
2024-07-26 09:34:51 +03:00
|
|
|
{
|
2024-10-11 21:23:02 +03:00
|
|
|
files: [
|
|
|
|
'app/gui/src/dashboard/**/*.ts',
|
|
|
|
'app/gui/src/dashboard/**/*.mts',
|
|
|
|
'app/gui/src/dashboard/**/*.cts',
|
|
|
|
'app/gui/src/dashboard/**/*.tsx',
|
|
|
|
'app/gui/src/dashboard/**/*.mtsx',
|
|
|
|
'app/gui/src/dashboard/**/*.ctsx',
|
|
|
|
],
|
2024-07-26 09:34:51 +03:00
|
|
|
settings: {
|
|
|
|
react: {
|
|
|
|
version: '18.2',
|
|
|
|
},
|
|
|
|
},
|
|
|
|
plugins: {
|
|
|
|
jsdoc: jsdoc,
|
|
|
|
'@typescript-eslint': tsEslint,
|
|
|
|
react: react,
|
|
|
|
'react-hooks': reactHooks,
|
2024-10-28 15:58:41 +03:00
|
|
|
'react-compiler': reactCompiler,
|
2024-07-26 09:34:51 +03:00
|
|
|
},
|
|
|
|
languageOptions: {
|
|
|
|
parserOptions: {
|
|
|
|
tsconfigRootDir: DIR_NAME,
|
2024-10-11 21:23:02 +03:00
|
|
|
projectService: true,
|
2024-07-26 09:34:51 +03:00
|
|
|
},
|
|
|
|
globals: {
|
|
|
|
...globals.browser,
|
|
|
|
...globals.node,
|
|
|
|
...globals.es2015,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
rules: {
|
|
|
|
...tsEslint.configs['eslint-recommended']?.rules,
|
|
|
|
...tsEslint.configs.recommended?.rules,
|
|
|
|
...tsEslint.configs['recommended-requiring-type-checking']?.rules,
|
|
|
|
...tsEslint.configs.strict?.rules,
|
|
|
|
...react.configs['jsx-runtime'].rules,
|
|
|
|
eqeqeq: ['error', 'always', { null: 'never' }],
|
|
|
|
// Any extra semicolons that exist, are required by Prettier.
|
|
|
|
'no-extra-semi': 'off',
|
|
|
|
'jsdoc/require-jsdoc': [
|
|
|
|
'error',
|
|
|
|
{
|
|
|
|
require: {
|
|
|
|
FunctionDeclaration: true,
|
|
|
|
MethodDefinition: true,
|
|
|
|
ClassDeclaration: true,
|
|
|
|
ArrowFunctionExpression: false,
|
|
|
|
FunctionExpression: true,
|
|
|
|
},
|
|
|
|
// Top-level constants should require JSDoc as well,
|
|
|
|
// however it does not seem like there is a way to do this.
|
|
|
|
contexts: [
|
|
|
|
'TSInterfaceDeclaration',
|
|
|
|
'TSEnumDeclaration',
|
|
|
|
'TSTypeAliasDeclaration',
|
|
|
|
'TSMethodSignature',
|
|
|
|
],
|
2023-06-19 02:02:08 +03:00
|
|
|
},
|
2024-07-26 09:34:51 +03:00
|
|
|
],
|
|
|
|
'no-constant-condition': ['error', { checkLoops: false }],
|
|
|
|
'no-restricted-syntax': ['error', ...RESTRICTED_SYNTAXES],
|
2024-10-11 21:23:02 +03:00
|
|
|
'no-restricted-properties': [
|
|
|
|
'error',
|
|
|
|
{ object: 'console', message: DEBUG_STATEMENTS_MESSAGE },
|
|
|
|
{ property: 'useDebugState', message: DEBUG_STATEMENTS_MESSAGE },
|
|
|
|
{ property: 'useDebugEffect', message: DEBUG_STATEMENTS_MESSAGE },
|
|
|
|
{ property: 'useDebugMemo', message: DEBUG_STATEMENTS_MESSAGE },
|
|
|
|
{ property: 'useDebugCallback', message: DEBUG_STATEMENTS_MESSAGE },
|
|
|
|
{
|
|
|
|
object: 'page',
|
|
|
|
property: 'type',
|
|
|
|
message: 'Prefer `locator.type` instead',
|
|
|
|
},
|
|
|
|
{
|
|
|
|
object: 'page',
|
|
|
|
property: 'click',
|
|
|
|
message: 'Prefer `locator.click` instead',
|
|
|
|
},
|
|
|
|
{
|
|
|
|
object: 'page',
|
|
|
|
property: 'fill',
|
|
|
|
message: 'Prefer `locator.fill` instead',
|
|
|
|
},
|
|
|
|
{
|
|
|
|
object: 'page',
|
|
|
|
property: 'locator',
|
|
|
|
message: 'Prefer `page.getBy*` instead',
|
|
|
|
},
|
|
|
|
],
|
2024-07-26 09:34:51 +03:00
|
|
|
'prefer-const': 'error',
|
|
|
|
'react/forbid-elements': [
|
|
|
|
'error',
|
|
|
|
{ forbid: [{ element: 'Debug', message: DEBUG_STATEMENTS_MESSAGE }] },
|
|
|
|
],
|
|
|
|
// Not relevant because TypeScript checks types.
|
|
|
|
'react/prop-types': 'off',
|
|
|
|
'react/self-closing-comp': 'error',
|
|
|
|
'react-hooks/rules-of-hooks': 'error',
|
2024-09-27 10:05:10 +03:00
|
|
|
'react-hooks/exhaustive-deps': ['error', { additionalHooks: 'useOnScroll' }],
|
2024-07-26 09:34:51 +03:00
|
|
|
'react/jsx-pascal-case': ['error', { allowNamespace: true }],
|
2024-10-28 15:58:41 +03:00
|
|
|
|
|
|
|
// We use warnings instead of errors because we want to gradually migrate the codebase to the new compiler.
|
|
|
|
// see: https://github.com/reactwg/react-compiler/discussions/8
|
|
|
|
'react-compiler/react-compiler': 'warn',
|
|
|
|
|
2024-07-26 09:34:51 +03:00
|
|
|
// Prefer `interface` over `type`.
|
|
|
|
'@typescript-eslint/consistent-type-definitions': 'error',
|
|
|
|
'@typescript-eslint/consistent-type-imports': 'error',
|
|
|
|
'@typescript-eslint/member-ordering': 'error',
|
|
|
|
// Method syntax is not type-safe.
|
|
|
|
// See: https://typescript-eslint.io/rules/method-signature-style
|
|
|
|
'@typescript-eslint/method-signature-style': 'error',
|
|
|
|
'@typescript-eslint/naming-convention': [
|
|
|
|
'error',
|
|
|
|
{
|
|
|
|
selector: ['function'],
|
|
|
|
// PascalCase for React components, camelCase for all other situations
|
|
|
|
format: ['camelCase', 'PascalCase'],
|
2023-03-15 06:42:14 +03:00
|
|
|
},
|
2024-07-26 09:34:51 +03:00
|
|
|
{
|
|
|
|
selector: ['variable'],
|
|
|
|
modifiers: ['const', 'global'],
|
|
|
|
format: ['UPPER_CASE', 'camelCase', 'PascalCase'],
|
2023-03-15 06:42:14 +03:00
|
|
|
},
|
2024-07-26 09:34:51 +03:00
|
|
|
{
|
|
|
|
selector: ['variable'],
|
|
|
|
modifiers: ['const', 'exported'],
|
|
|
|
format: ['UPPER_CASE', 'camelCase', 'PascalCase'],
|
2023-03-15 06:42:14 +03:00
|
|
|
},
|
2024-07-26 09:34:51 +03:00
|
|
|
{
|
|
|
|
selector: ['variable'],
|
|
|
|
format: ['camelCase', 'PascalCase'],
|
2023-03-15 06:42:14 +03:00
|
|
|
},
|
2024-07-26 09:34:51 +03:00
|
|
|
{
|
|
|
|
selector: ['parameter', 'method'],
|
|
|
|
format: ['camelCase'],
|
2023-03-15 06:42:14 +03:00
|
|
|
},
|
2024-07-26 09:34:51 +03:00
|
|
|
{
|
|
|
|
selector: ['parameter'],
|
|
|
|
modifiers: ['unused'],
|
|
|
|
format: ['camelCase'],
|
|
|
|
leadingUnderscore: 'require',
|
2023-06-06 15:00:07 +03:00
|
|
|
},
|
2024-07-26 09:34:51 +03:00
|
|
|
{
|
|
|
|
selector: ['property'],
|
|
|
|
format: ['camelCase'],
|
|
|
|
filter: {
|
|
|
|
regex: '^(?:data-testid)$',
|
|
|
|
match: false,
|
|
|
|
},
|
2023-10-11 13:24:33 +03:00
|
|
|
},
|
2024-07-26 09:34:51 +03:00
|
|
|
],
|
|
|
|
'@typescript-eslint/no-confusing-void-expression': 'error',
|
|
|
|
'@typescript-eslint/no-empty-interface': 'off',
|
|
|
|
'@typescript-eslint/no-extraneous-class': 'error',
|
|
|
|
'@typescript-eslint/no-invalid-void-type': ['error', { allowAsThisParameter: true }],
|
|
|
|
// React 17 and later supports async functions as event handlers, so we need to disable this
|
|
|
|
// rule to avoid false positives.
|
|
|
|
//
|
|
|
|
// See: https://github.com/typescript-eslint/typescript-eslint/pull/4623
|
|
|
|
'@typescript-eslint/no-misused-promises': [
|
|
|
|
'error',
|
|
|
|
{ checksVoidReturn: { attributes: false } },
|
|
|
|
],
|
|
|
|
'@typescript-eslint/no-redundant-type-constituents': 'error',
|
|
|
|
'@typescript-eslint/no-unnecessary-condition': [
|
|
|
|
'error',
|
|
|
|
{ allowConstantLoopConditions: true },
|
|
|
|
],
|
|
|
|
'@typescript-eslint/no-useless-empty-export': 'error',
|
|
|
|
'@typescript-eslint/parameter-properties': ['error', { prefer: 'parameter-property' }],
|
|
|
|
'@typescript-eslint/prefer-enum-initializers': 'error',
|
|
|
|
'@typescript-eslint/prefer-readonly': 'error',
|
|
|
|
'@typescript-eslint/require-array-sort-compare': ['error', { ignoreStringArrays: true }],
|
|
|
|
'@typescript-eslint/restrict-template-expressions': 'error',
|
|
|
|
'@typescript-eslint/sort-type-constituents': 'error',
|
|
|
|
'@typescript-eslint/strict-boolean-expressions': 'error',
|
|
|
|
'@typescript-eslint/switch-exhaustiveness-check': 'error',
|
|
|
|
'default-param-last': 'off',
|
|
|
|
'@typescript-eslint/default-param-last': 'error',
|
|
|
|
'no-invalid-this': 'off',
|
|
|
|
'@typescript-eslint/no-invalid-this': ['error', { capIsConstructor: false }],
|
|
|
|
'jsdoc/no-magic-numbers': 'off',
|
|
|
|
'@typescript-eslint/no-magic-numbers': [
|
|
|
|
'error',
|
|
|
|
{
|
|
|
|
ignore: [-1, 0, 1, 2, 3, 4, 5],
|
|
|
|
ignoreArrayIndexes: true,
|
|
|
|
ignoreEnums: true,
|
|
|
|
detectObjects: true,
|
|
|
|
enforceConst: true,
|
2023-03-17 18:26:59 +03:00
|
|
|
},
|
2024-07-26 09:34:51 +03:00
|
|
|
],
|
|
|
|
'no-redeclare': 'off',
|
|
|
|
// Important to warn on accidental duplicated `interface`s e.g. when writing API wrappers.
|
|
|
|
'@typescript-eslint/no-redeclare': ['error', { ignoreDeclarationMerge: false }],
|
|
|
|
'no-shadow': 'off',
|
|
|
|
'@typescript-eslint/no-shadow': 'error',
|
|
|
|
'no-unused-expressions': 'off',
|
|
|
|
'@typescript-eslint/no-unused-expressions': 'error',
|
|
|
|
'jsdoc/require-param-type': 'off',
|
|
|
|
'jsdoc/check-access': 'error',
|
|
|
|
'jsdoc/check-alignment': 'error',
|
|
|
|
'jsdoc/check-indentation': 'error',
|
|
|
|
'jsdoc/check-line-alignment': 'error',
|
|
|
|
'jsdoc/check-param-names': 'error',
|
|
|
|
'jsdoc/check-property-names': 'error',
|
|
|
|
'jsdoc/check-syntax': 'error',
|
|
|
|
'jsdoc/check-tag-names': 'error',
|
|
|
|
'jsdoc/check-types': 'error',
|
|
|
|
'jsdoc/check-values': 'error',
|
|
|
|
'jsdoc/empty-tags': 'error',
|
|
|
|
'jsdoc/implements-on-classes': 'error',
|
|
|
|
'jsdoc/no-bad-blocks': 'error',
|
|
|
|
'jsdoc/no-defaults': 'error',
|
|
|
|
'jsdoc/no-multi-asterisks': 'error',
|
|
|
|
'jsdoc/no-types': 'error',
|
|
|
|
'jsdoc/no-undefined-types': 'error',
|
|
|
|
'jsdoc/require-asterisk-prefix': 'error',
|
|
|
|
'jsdoc/require-description': 'error',
|
|
|
|
// This rule does not handle `# Heading`s and "etc.", "e.g.", "vs." etc.
|
|
|
|
// 'jsdoc/require-description-complete-sentence': 'error',
|
|
|
|
'jsdoc/require-file-overview': 'error',
|
|
|
|
'jsdoc/require-hyphen-before-param-description': 'error',
|
|
|
|
'jsdoc/require-param-description': 'error',
|
|
|
|
'jsdoc/require-param-name': 'error',
|
|
|
|
'jsdoc/require-property': 'error',
|
|
|
|
'jsdoc/require-property-description': 'error',
|
|
|
|
'jsdoc/require-property-name': 'error',
|
|
|
|
'jsdoc/require-property-type': 'error',
|
|
|
|
'jsdoc/require-returns-check': 'error',
|
|
|
|
'jsdoc/require-returns-description': 'error',
|
|
|
|
'jsdoc/require-throws': 'error',
|
|
|
|
'jsdoc/require-yields': 'error',
|
|
|
|
'jsdoc/require-yields-check': 'error',
|
|
|
|
'jsdoc/tag-lines': 'error',
|
|
|
|
'jsdoc/valid-types': 'error',
|
|
|
|
},
|
|
|
|
},
|
|
|
|
{
|
|
|
|
files: ['**/*.js', '**/*.jsx', '**/*.cjs', '**/*.mjs'],
|
2024-08-08 15:12:05 +03:00
|
|
|
ignores: ['**/build.mjs'],
|
2024-07-26 09:34:51 +03:00
|
|
|
rules: {
|
|
|
|
'@typescript-eslint/no-var-requires': 'off',
|
|
|
|
// Parameter types must be specified using JSDoc in JS files.
|
|
|
|
'jsdoc/no-types': 'off',
|
|
|
|
},
|
|
|
|
},
|
|
|
|
{
|
2024-10-11 21:23:02 +03:00
|
|
|
files: [
|
|
|
|
'app/gui/src/dashboard/**/*.ts',
|
|
|
|
'app/gui/src/dashboard/**/*.mts',
|
|
|
|
'app/gui/src/dashboard/**/*.cts',
|
|
|
|
'app/gui/src/dashboard/**/*.tsx',
|
|
|
|
'app/gui/src/dashboard/**/*.mtsx',
|
|
|
|
'app/gui/src/dashboard/**/*.ctsx',
|
|
|
|
],
|
2024-07-26 09:34:51 +03:00
|
|
|
ignores: ['**/*.d.ts'],
|
|
|
|
rules: {
|
|
|
|
'no-restricted-syntax': [
|
|
|
|
'error',
|
|
|
|
...RESTRICTED_SYNTAXES,
|
|
|
|
{
|
|
|
|
selector: ':not(TSModuleDeclaration)[declare=true]',
|
|
|
|
message: 'No ambient declarations',
|
2023-12-06 10:50:44 +03:00
|
|
|
},
|
2024-07-26 09:34:51 +03:00
|
|
|
],
|
|
|
|
// This rule does not work with TypeScript, and TypeScript already does this.
|
|
|
|
'no-undef': 'off',
|
|
|
|
},
|
|
|
|
},
|
2023-03-15 06:42:14 +03:00
|
|
|
]
|