dify/web/docs/lint.md

2.3 KiB

Lint Guide

We use ESLint and Typescript to maintain code quality and consistency across the project.

ESLint

Common Flags

File/folder targeting: Append paths to lint specific files or directories.

pnpm eslint [options] file.js [file.js] [dir]

--cache: Caches lint results for faster subsequent runs. Keep this enabled by default; only disable when you encounter unexpected lint results.

--concurrency: Enables multi-threaded linting. Use --concurrency=auto or experiment with specific numbers to find the optimal setting for your machine. Keep this enabled when linting multiple files.

--fix: Automatically fixes auto-fixable rule violations. Always review the diff before committing to ensure no unintended changes.

--quiet: Suppresses warnings and only shows errors. Useful when you want to reduce noise from existing issues.

--suppress-all: Temporarily suppresses error-level violations and records them, allowing CI to pass. Treat this as an escape hatch—fix these errors when time permits.

--prune-suppressions: Removes outdated suppressions after you've fixed the underlying errors.

Type-Aware Linting

Some ESLint rules require type information, such as no-leaked-conditional-rendering. However, typed linting via typescript-eslint is too slow for practical use, so we use TSSLint instead.

pnpm lint:tss

This command lints the entire project and is intended for final verification before committing or pushing changes.

Type Check

You should be able to see suggestions from TypeScript in your editor for all open files.

However, it can be useful to run the TypeScript 7 command-line (tsgo) to type check all files:

pnpm type-check:tsgo

Prefer using tsgo for type checking as it is significantly faster than the standard TypeScript compiler. Only fall back to pnpm type-check (which uses tsc) if you encounter unexpected results.