embed-eslint
raw JSON → 3.1.0 verified Fri May 01 auth: no javascript
ESLint integration for embedded TypeScript compilation. Version 3.1.0 provides a runtime ESLint compiler that extends embed-typescript, allowing linting during TypeScript compilation within Node.js or browser applications. Released as part of the embed-typescript monorepo with periodic updates. Key differentiator: unified diagnostics where ESLint violations are reported as TypeScript diagnostics, with full support for type-aware @typescript-eslint rules. Requires peer dependencies: embed-typescript, typescript, eslint, @typescript-eslint/parser, and @typescript-eslint/eslint-plugin.
Common errors
error Cannot find module 'embed-eslint' or its corresponding type declarations. ↓
cause The package is not installed or is not in the project's node_modules.
fix
Install the package: npm install embed-eslint
error Module 'embed-eslint' has no exported member 'EmbedEsLint'. ↓
cause Importing from wrong path or using wrong import style (e.g., default import instead of named).
fix
Use correct named import: import { EmbedEsLint } from 'embed-eslint'
error Error: ESLint configuration is invalid: Cannot find module '@typescript-eslint/parser' ↓
cause Missing peer dependency @typescript-eslint/parser.
fix
Install the missing dependency: npm install @typescript-eslint/parser
Warnings
breaking Starting from v2.0.0, embed-eslint was extracted into its own package from embed-typescript. If you were using embed-typescript's built-in ESLint support before v2, you must now install and import from embed-eslint separately. ↓
fix Install embed-eslint and change imports from 'embed-typescript' to 'embed-eslint' for ESLint functionality.
deprecated The IEmbedTypeScriptDiagnostic.file property was incorrectly typed in v2.0.0; fixed in v2.0.1. Users relying on the broken property may have incorrect file references. ↓
fix Upgrade to v2.0.1 or higher.
gotcha All peer dependencies (embed-typescript, typescript, eslint, @typescript-eslint/parser, @typescript-eslint/eslint-plugin) must be installed separately. Missing one will cause runtime errors. ↓
fix Run: npm install embed-typescript typescript eslint @typescript-eslint/parser @typescript-eslint/eslint-plugin
gotcha ESLint rules that require type information (e.g., @typescript-eslint/no-floating-promises) only work if the compiler options include type checking (e.g., 'noEmit: false' or 'declaration: true'). ↓
fix Ensure your compilerOptions include 'strict: true' or set 'noEmit: false' to enable type-aware lint rules.
Install
npm install embed-eslint yarn add embed-eslint pnpm add embed-eslint Imports
- EmbedEsLint wrong
const EmbedEsLint = require('embed-eslint')correctimport { EmbedEsLint } from 'embed-eslint' - IEmbedEsLintProps wrong
import { IEmbedEsLintProps } from 'embed-eslint'correctimport type { IEmbedEsLintProps } from 'embed-eslint' - EmbedTypeScript wrong
import { EmbedTypeScript } from 'embed-eslint'correctimport { EmbedTypeScript } from 'embed-typescript'
Quickstart
import { EmbedEsLint } from 'embed-eslint';
import ts from 'typescript';
const compiler = new EmbedEsLint({
compilerOptions: {
target: ts.ScriptTarget.ES2015,
module: ts.ModuleKind.CommonJS,
strict: true,
},
rules: {
'@typescript-eslint/no-floating-promises': 'error',
'@typescript-eslint/no-unused-vars': 'warn',
'@typescript-eslint/explicit-function-return-type': 'error',
'no-console': 'warn',
'no-debugger': 'error',
},
});
const result = compiler.compile({
'src/index.ts': `
async function fetchData() {
console.log('Fetching data...');
return { data: 'test' };
}
fetchData();
const unused = 42;
`,
});
if (!result.success) {
for (const diagnostic of result.diagnostics) {
console.log(
diagnostic.severity + ': ' + diagnostic.message +
' at ' + diagnostic.file + ':' + diagnostic.start?.line + ':' + diagnostic.start?.column
);
}
}