Polymer Linter
raw JSON → 3.0.1 verified Fri May 01 auth: no javascript deprecated
Polymer Linter (v3.0.1) is a library for finding suspicious patterns and errors in web projects using Polymer custom elements. It is built on the Polymer Analyzer and provides AST-based linting with high-level feature queries. The linter is typically run via Polymer CLI or integrated into editors like VS Code. It offers rule collections (e.g., polymer-2-hybrid) and individual rules. Release cadence is low, as the project is in maintenance mode. Key differentiators: Polymer-specific linting rules (e.g., attribute checks, behaviors spelling) and tight integration with Polymer toolchain.
Common errors
error Error: Cannot find module 'polymer-analyzer' ↓
cause Missing dependency polymer-analyzer when using polymer-linter programmatically.
fix
npm install polymer-analyzer
error TypeError: linter.lint is not a function ↓
cause Using old v2 API where lint was called differently; v3 lint method expects (document, options).
fix
Update code to: linter.lint(document, { rules: ['polymer-2-hybrid'] })
error Warning: No rules matched; nothing to lint. ↓
cause Specified rule collection name is misspelled or not registered.
fix
Check rule names in registry; use correct string like 'polymer-2-hybrid'.
Warnings
deprecated Polymer Linter is deprecated and no longer maintained. Polymer 3+ does not use this linter. ↓
fix Migrate to lit-analyzer or eslint-plugin-lit for Polymer 3 and LitElement projects.
breaking The API changed significantly from v2 to v3. Linter constructor now requires an Analyzer instance. ↓
fix Instantiate polymer-analyzer and pass it to Linter.
breaking Rule collections are now specified as strings in an array (e.g., ['polymer-2-hybrid']), not as separate arguments. ↓
fix Pass rules as array in options object.
gotcha The linter depends on polymer-analyzer which loads files via URL loader. No built-in file system loader. ↓
fix Provide a custom urlLoader or use polymer-cli to run it.
Install
npm install polymer-linter yarn add polymer-linter pnpm add polymer-linter Imports
- Linter wrong
const Linter = require('polymer-linter').Lintercorrectimport { Linter } from 'polymer-linter' - Warning wrong
const Warning = require('polymer-linter').Warningcorrectimport { Warning } from 'polymer-linter' - registry wrong
import registry from 'polymer-linter'correctimport { registry } from 'polymer-linter'
Quickstart
import { Linter } from 'polymer-linter';
import { Analyzer } from 'polymer-analyzer';
const analyzer = new Analyzer({ urlLoader: { canLoad: () => false, load: () => '', request: () => '' } });
const linter = new Linter(analyzer);
// See available rules
console.log(linter.registry.rules);
// Create a lint result
const doc = await analyzer.analyze('file.html');
const warnings = await linter.lint(doc, { rules: ['polymer-2-hybrid'] });
for (const warning of warnings) {
console.log(warning.message);
}