Important: This documentation covers Yarn 1 (Classic).
For Yarn 2+ docs and migration guide, see yarnpkg.com.

Package detail

eslint-plugin-wc

43081j213.6kMIT3.0.1TypeScript support: included

ESLint plugin for Web Components

eslint, eslintplugin, webcomponents, wc

readme

Eslint + WebComponents

eslint-plugin-wc

npm version Build Status Coverage Status License: MIT

ESLint plugin for Web Components.

Install

Assuming you already have ESLint installed, run:

# npm
npm install eslint-plugin-wc --save-dev

# yarn
yarn add eslint-plugin-wc --dev

Usage

Then extend the recommended eslint config:

{
  "extends": [
    // ...
    "plugin:wc/recommended"
  ]
}

Or if you're using ESLint flat configs, add this to your eslint.config.js:

import {configs} from 'eslint-plugin-wc';

export default [
  configs['flat/recommended'],

  // or if you want to specify `files`, or other options
  {
    ...configs['flat/recommended'],
    files: ['test/**/*.js']
  }
];

You should also specify settings that will be shared across all the plugin rules. (More about eslint shared settings)

{
  "settings": {
    "wc": {
      "elementBaseClasses": ["LitElement"] // Recognize `LitElement` as a Custom Element base class
    }
  }
}

Custom Configuration

If you want more fine-grained configuration, you can instead add a snippet like this to your ESLint configuration file:

{
  "plugins": [
    // ...
    "wc"
  ],
  "rules": {
    // ...
    "wc/no-invalid-element-name": "error",
    "wc/no-typos": "warn"
  }
}

Supported Rules

Best Practice

Preference/convention

Shareable configurations

This plugin exports a recommended configuration that enforces WebComponent good practices.

To enable this configuration use the extends property in your .eslintrc config file:

{
  "extends": ["eslint:recommended", "plugin:wc/recommended"]
}

Best Practices

This plugin exports a best-practice configuration that enforces WebComponent best practices.

To enable this configuration use the extends property in your .eslintrc config file:

{
  "extends": ["eslint:recommended", "plugin:wc/best-practice"]
}

Note: These configurations will enable sourceType: 'module' in parser options.

License

eslint-plugin-wc is licensed under the MIT License.

changelog

Change Log

All notable changes to this project will be documented in this file.

The format is based on Keep a Changelog and this project adheres to Semantic Versioning.

[1.2.0] - 2019-07-31

Added

  • Custom elements can now be detected via a new setting (settings.wc.elementBaseClasses)

[1.1.1] - 2019-06-10

Fixed

  • Updated dependencies to resolve security audits

[1.1.0] - 2019-05-13

Added

  • Support for @customElement JSDoc tag introduced such that classes with such a tag are detected as custom elements and linted correctly.

[1.0.0] - 2019-02-26

Fixed

  • Validate element name even when specifying window.customElements
  • Added parserOptions.sourceType of 'module' to recommended config.

[0.1.1] - 2019-02-26

Fixed

  • Added namespace to rules in configurations (wc/)

[0.1.0] - 2019-02-26

Added

  • Initial release