Socket
Book a DemoInstallSign in
Socket

@manifoldco/eslint-plugin-stencil

Package Overview
Dependencies
Maintainers
20
Versions
6
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@manifoldco/eslint-plugin-stencil

ESLint rules to enforce better practices in Stencil development

0.4.1
latest
Source
npmnpm
Version published
Weekly downloads
1
-95%
Maintainers
20
Weekly downloads
 
Created
Source

eslint-plugin-stencil

ESLint rules to enforce better practices in Stencil development

Code of Conduct | Contribution Guidelines

GitHub release

Travis

License

Install

Download to your dev dependencies from npm.

npm i -D @manifoldco/eslint-plugin-stencil

Integrating the Plugin

First, add to the plugins array of your ESLint configuration.

// .eslintrc.js
module.exports = {
  plugins: ['@manifoldco/stencil'],
  parser: '@typescript-eslint/parser',
  parserOptions: {
    ecmaFeatures: {
      legacyDecorators: true,
      jsx: true,
    },
  },
  settings: {
    'import/parsers': {
      '@typescript-eslint/parser': ['.ts', '.tsx'],
    },
    'import/resolver': {
      typescript: {},
    },
  },

If you're not already linting your Stencil project, you'll want to use @typescript-eslint/parser with the parser options and settings shown above.

Configuring Rules

This plugin comes with two rules, which need to be added and configured individually within your ESLint configuration. Explanation of these rules, including their reasoning and integration instructions, is listed below.

restrict-required-props

This rule limits which component props can be required. Stencil components can accept props of all types, but when using web components from HTML, only legal HTML attributes can be added as props. In order to add object, array, or numeric props to a web component, you need to access your element from JavaScript. For this reason, this rule will ensure that any component prop that isn't a legal HTML attribute type must either be optional or declare a default value.

To turn this rule on for your project, add it to the rules field in your ESLint configuration:

// .eslintrc.js
  rules: {
    '@manifoldco/stencil/restrict-required-props': 'error',

component-prefix

This rule exists to enforce a consistent naming convention for all your web components. This will help your consumers avoid naming collisions when using more than one web component library.

To turn this rule on for your project, add it to the rules field in your ESLint configuration, and specify a prefix. For example, if you want all of your web components to be prefixed with scalawags-:

// .eslintrc.js
  rules: {
    '@manifoldco/stencil/component-prefix': ['error', { prefix: 'scalawags-' }],

require-render-decorator

This rule requires all Stencil components to decorate their render methods with a given decorator. This allows you to simulate something React's error boundaries. For instance, your decorator can wrap the render method in a try/catch, where the catch block can send errors to a logging service and display an error message to the user.

To turn this rule on for your project, add it to the rules field in your ESLint configuration. By default, the decorator name will be logger, but you can override this in the options array:

// .eslintrc.js
  rules: {
    '@manifoldco/stencil/require-render-logger': ['error', { decaratorName: 'renAndStimpyLoveLogs' }],

Keywords

eslint

FAQs

Package last updated on 31 Jul 2019

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

About

Packages

Stay in touch

Get open source security insights delivered straight into your inbox.

  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc

U.S. Patent No. 12,346,443 & 12,314,394. Other pending.