@edge-lint/core
v0.1.4
Published
Core linting engine for Edge.js templates
Readme
@edge-lint/core
Core linting engine for Edge.js templates.
Installation
npm install @edge-lint/coreUsage
import { Linter } from '@edge-lint/core';
const linter = new Linter({
config: {
rules: {
'no-empty-mustache': 'error',
'mustache-spacing': ['warn', 'always'],
},
},
});
// Lint and get messages
const messages = linter.verify(template, 'template.edge');
// Lint and auto-fix
const result = linter.verifyAndFix(template, 'template.edge');
console.log(result.output); // Fixed source
console.log(result.messages); // Remaining issuesAPI
Linter
Main class for linting Edge.js templates.
Constructor Options
interface LinterOptions {
config?: {
rules?: Record<string, RuleSeverity | [RuleSeverity, ...unknown[]]>;
parserOptions?: {
tags?: Record<string, TagDefinition>;
};
};
}Methods
verify(source: string, filename?: string): LintMessage[]- Lint source and return messagesverifyAndFix(source: string, filename?: string): { output: string; messages: LintMessage[]; fixed: boolean }- Lint and apply fixes
SourceCode
Wraps source text and tokens with utilities.
const sourceCode = new SourceCode(source, tokens);
sourceCode.getText(token); // Get token text
sourceCode.getRange(token); // Get [start, end] range
sourceCode.getLines(); // Get array of linesBuilt-in Rules
| Rule | Description | Fixable |
|------|-------------|---------|
| no-empty-mustache | Disallow empty mustache expressions | No |
| valid-expression | Validate JavaScript expressions | No |
| no-unknown-tag | Warn on unregistered Edge tags | No |
| no-unused-let | Detect unused @let variables | No |
| prefer-safe-mustache | Suggest safe mustache for HTML | No |
| mustache-spacing | Enforce consistent spacing | Yes |
License
MIT
