Diplodoc platform internal utility set for linting
npm install @diplodoc/lint
Centralized linting and code formatting toolkit for Diplodoc projects. Combines ESLint, Prettier, and Stylelint configurations and automates their setup.
- Automatic setup — one command to initialize all tools
- Automatic updates — synchronizes configurations across packages
- Metapackage and standalone support — works as part of the metapackage and as a standalone npm package
- Unified standards — shared linting rules for all Diplodoc packages
- Git hooks — automatic pre-commit hook setup via Husky
- TypeScript/JavaScript — full support for both languages
- CSS/SCSS — style support via Stylelint
``bash`
npm install --save-dev @diplodoc/lint
Run the initialization command in your package root:
`bash`
npx @diplodoc/lint init
This command will:
- Add necessary scripts to package.json.eslintrc.js
- Create configuration files (, .prettierrc.js, .stylelintrc.js).gitignore
- Set up Git hooks via Husky
- Update , .eslintignore, .prettierignore, .stylelintignore
After initialization, commit the changes:
`bash`
git add --all && git commit -m 'chore: init lint'
Code checking:
`bash`
npm run lint
Automatic fixing:
`bash`
npm run lint:fix
Update configurations:
`bash`
npx @diplodoc/lint update
> Note: The update command runs automatically before each check (npm run lint), so configurations are always up-to-date.
Initializes linting in a package:
- Adds scripts to package.json:lint
- — code checkinglint:fix
- — automatic fixingpre-commit
- — pre-commit checkingprepare
- — Husky setupscaffolding/
- Copies configuration files from
- Sets up Husky for Git hooks
- Updates ignore files
Updates configuration files to the latest versions:
- Updates .eslintrc.js, .prettierrc.js, .stylelintrc.jspackage.json
- Updates ignore files with new patterns
- Does not re-initialize Husky
- Does not modify existing scripts in
> Important: This command runs automatically before lint and lint fix, so configurations are always synchronized.
Checks code for rule compliance:
1. Automatically runs lint update
2. Runs ESLint for JavaScript/TypeScript files
3. Runs Prettier for formatting checks
4. Runs Stylelint for CSS/SCSS files (if present)
Automatically fixes found issues:
1. Automatically runs lint update--fix
2. Runs ESLint with flag--write
3. Runs Prettier with flag--fix
4. Runs Stylelint with flag (if CSS/SCSS files exist)
The following configuration files are automatically generated and updated by @diplodoc/lint:
- .eslintrc.js.prettierrc.js
- .stylelintrc.js
- .lintstagedrc.js
- .eslintignore
- .prettierignore
- .stylelintignore
- .gitignore
- (patterns are added automatically)
⚠️ DO NOT EDIT THESE FILES MANUALLY — any changes will be overwritten on the next lint update (which runs automatically before each lint command).
If you need to customize configuration:
1. Check if the customization can be done via package-level overrides (see below)
2. If not, consider opening an issue or PR to @diplodoc/lint to add the feature@diplodoc/lint
3. For ignore patterns, they are managed automatically — if you need additional patterns, they should be added to 's modify-ignore.js script
After initialization, the following files are created in the package root:
`javascript`
module.exports = {
root: true,
extends: require.resolve('@diplodoc/lint/eslint-config'),
parserOptions: {
tsconfigRootDir: __dirname,
project: true,
},
};
Packages can extend the configuration at the src/ level, but should not override base settings.
`javascript`
module.exports = require('@diplodoc/lint/prettier-config');
`javascript`
module.exports = {
extends: require.resolve('@diplodoc/lint/stylelint-config'),
};
Created only if CSS/SCSS files exist in the project.
- Configurations for TypeScript and JavaScript
- React support (via eslint-config/client)eslint-config/node
- Node.js support (via )
- Project-aware TypeScript parsing
- Unified formatting style for all packages
- Automatic formatting on save (via editor)
- CSS and SCSS support
- Uses @gravity-ui/stylelint-config as base
- Git hooks management
- Pre-commit hook runs lint-staged
- Checks only changed files
- Fast pre-commit checking
The package exposes a pinned esbuild version via the @diplodoc/lint/esbuild subpath so that build scripts use a single, consistent esbuild across Diplodoc packages without each package declaring its own esbuild dependency.
Usage (e.g. in esbuild/build.mjs):
`javascript
import {build} from '@diplodoc/lint/esbuild';
build({
entryPoints: ['src/plugin/index.ts'],
outfile: 'build/plugin/index.js',
bundle: true,
platform: 'node',
packages: 'external',
});
build({
entryPoints: ['src/runtime/index.ts'],
outfile: 'build/runtime/index.js',
minify: true,
platform: 'browser',
plugins: [sassPlugin()],
});
`
- Import: Use @diplodoc/lint/esbuild — it re-exports the full esbuild API (ESM and CJS).@diplodoc/lint
- Why: Aligns esbuild version and avoids duplicate native bindings; add as a devDependency and use this export instead of installing esbuild directly in the package.
The package works in two modes:
When the package is installed as part of the metapackage via npm workspaces:
- Dependencies are resolved through shared node_modulespackage-lock.json
- Commands work through workspace links
- is managed at the metapackage level
When the package is used as a standalone npm package:
- All dependencies are installed locally
- Commands work through node_modules/.binpackage-lock.json
- For management, use npm i --no-workspaces --package-lock-only
Both modes are supported automatically — the package detects the context and works accordingly.
After lint init, the following scripts are added to package.json:
`json`
{
"scripts": {
"lint": "lint update && lint",
"lint:fix": "lint update && lint fix",
"pre-commit": "lint update && lint-staged",
"prepare": "husky"
}
}
- lint — code checking (with auto-update)lint:fix
- — automatic fixing (with auto-update)pre-commit
- — pre-commit checking (runs via Husky)prepare
- — Husky setup when installing dependencies
The package automatically updates the following ignore files:
- .gitignore — system files, dependencies, artifacts.eslintignore
- — system files, dependencies, artifacts, test/, scripts/, build/, esbuild/.prettierignore
- — system files, dependencies, artifacts.stylelintignore
- — system files, dependencies, artifacts
⚠️ These files are auto-generated — patterns are added automatically on init and update, duplicates are not created. Manual edits will be overwritten.
If you need additional ignore patterns, they should be added to @diplodoc/lint's modify-ignore.js script.
The package includes a comprehensive test suite (37 tests):
`bashRun all tests
npm test
Tests use Node.js built-in
assert module and require no external dependencies.Development
$3
`
@diplodoc/lint/
├── bin/ # Executable scripts
│ ├── lint # Main script
│ ├── eslint # ESLint proxy
│ ├── prettier # Prettier proxy
│ └── ...
├── scripts/ # Helper scripts
│ ├── modify-package.js
│ └── modify-ignore.js
├── scaffolding/ # Configuration templates
│ ├── .eslintrc.js
│ ├── .prettierrc.js
│ └── ...
└── test/ # Tests
├── unit/
├── integration/
└── helpers/
`$3
1. Make code changes
2. Run tests:
npm test
3. Check linting: npm run lint
4. Test in a test package: npx @diplodoc/lint initImportant Notes
- Auto-update: The
lint update command runs automatically on each lint execution, ensuring configuration synchronization
- Backward compatibility: When updating configs, backward compatibility is considered. Breaking changes require major version bumps
- Package independence: This package does not depend on other Diplodoc packages (except devops infrastructure)
- Replaces deprecated packages: This package replaces @diplodoc/eslint-config and @diplodoc/prettier-config`. Do not use deprecated packagesMIT