razor-vue-lint
raw JSON → 1.1.10 verified Fri May 01 auth: no javascript
An ESLint preprocessor for .NET Razor (.cshtml) views containing inline Vue.js templates. Version 1.1.10 wraps Razor expressions (e.g. @Html.PropertyFor) inside /* eslint-disable */ and /* eslint-enable */ comment blocks so that ESLint only lints the Vue template portions. It supports three expression patterns: newline-terminated, closing-tag-terminated, and attribute-enclosed. The library is extensible via custom regex matchers and matcher keys. Released on npm, with low release cadence. Key differentiator: solves a niche problem of linting Vue code embedded in C# Razor views. Not widely adopted; consider manual ESLint configuration as an alternative.
Common errors
error Cannot find module 'razor-vue-lint' or its corresponding type declarations. ↓
cause TypeScript project not finding types; package has no bundled types.
fix
Install @types/razor-vue-lint (if available) or create a declaration file: declare module 'razor-vue-lint';
error Uncaught SyntaxError: The requested module 'razor-vue-lint' does not provide an export named 'esLintEscapeRazorExpressions' ↓
cause Using require() in an ESM context; the package is ESM-only.
fix
Use import instead of require(): import { esLintEscapeRazorExpressions } from 'razor-vue-lint';
error TypeError: esLintEscapeRazorExpressions is not a function ↓
cause Importing the default export instead of named export.
fix
Use import { esLintEscapeRazorExpressions } from 'razor-vue-lint'; not import razorVueLint from 'razor-vue-lint';
Warnings
gotcha Not all Razor expression patterns are supported; only those terminated by newline, closing tag, or single quotes. Complex expressions may not be escaped. ↓
fix Contribute custom matchers via options or manually wrap unsupported expressions with /* eslint-disable */ and /* eslint-enable */.
deprecated Function addIgnoreEsLintBlocksForRazorExpressions is undocumented and may be removed. Use esLintEscapeRazorExpressions instead. ↓
fix Replace addIgnoreEsLintBlocksForRazorExpressions with esLintEscapeRazorExpressions.
gotcha Package has not been updated since initial release; no active maintenance. Could break with future ESLint versions. ↓
fix Consider writing a custom ESLint plugin or preprocessor for .cshtml files instead.
Install
npm install razor-vue-lint yarn add razor-vue-lint pnpm add razor-vue-lint Imports
- esLintEscapeRazorExpressions wrong
const razorVueLint = require('razor-vue-lint'); razorVueLint.esLintEscapeRazorExpressions(code);correctimport { esLintEscapeRazorExpressions } from 'razor-vue-lint' - addIgnoreEsLintBlocksForRazorExpressions wrong
import { esLintEscapeRazorExpressions } from 'razor-vue-lint'; // wrong function namecorrectimport { addIgnoreEsLintBlocksForRazorExpressions } from 'razor-vue-lint' - default wrong
import { default } from 'razor-vue-lint';correctimport razorVueLint from 'razor-vue-lint'; razorVueLint.esLintEscapeRazorExpressions(code);
Quickstart
import { esLintEscapeRazorExpressions } from 'razor-vue-lint';
import { readFileSync, writeFileSync } from 'fs';
import { globSync } from 'glob';
const files = globSync('**/*.cshtml');
for (const file of files) {
const original = readFileSync(file, 'utf-8');
const lintSafe = esLintEscapeRazorExpressions(original);
writeFileSync(file.replace('.cshtml', '.lint.cshtml'), lintSafe);
console.log(`Processed ${file}`);
}