@locker/eslint-rule-maker
TypeScript icon, indicating that this package has built-in type declarations

0.21.5 • Public • Published

@locker/eslint-rule-maker

Lightning Web Security ESLint rule maker utilities

Installation

$ yarn add @locker/eslint-rule-maker

Usage

Define a rule using createRule(config).

const { createRule, matchers } = require('@locker/eslint-rule-maker');

module.exports = createRule({
    rule: {
        // The message provided to `context.report()`.
        message: 'Use of window.top is prohibited.',
        // The array of object property paths to search for.
        search: ['window.top'],
        // The optional fix function or string provided to `context.report()`.
        // https://eslint.org/docs/developer-guide/working-with-rules#contextreport
        fix: 'window',
        // The optional meta object.
        // https://eslint.org/docs/developer-guide/working-with-rules#rule-basics
        meta: {
            // The following default values are provided:
            //     fixable: 'code' (when specifying `rule.fix`)
            //     type: 'problem'
        },
        // Choose an optional match handler from the exported `matchers` object
        // or specify a custom one. The following `matchers` are available:
        //     - `matchers.matchAsNonReadableNonWritable` (default)
        //       Reports access or assignments to matches.
        //
        //     - `matchers.matchAsNonWritable`
        //       Reports assignments to matches.
        //
        //     - `matchers.matchAsNullishAndNonWritable`
        //       Reports property access on, or assignments to, matches.
        //
        // Matchers are passed a match `data` object and should return a
        // boolean indicating whether the match succeeded. Match `data` contains
        // the following properties:
        //     - `data.context`
        //       The ESLint rule context object.
        //       https://eslint.org/docs/developer-guide/working-with-rules#the-context-object
        //
        //     - `data.identifier`
        //       The matched identifier node, e.g. representing `top`.
        //
        //     - `data.node`
        //       The matched node, e.g. representing `window.top`.
        //
        //     - `data.pattern`
        //       The matched search pattern, e.g. 'window.top'.
        onMatch: matchers.matchAsNullishAndNonWritable,
    },
});

Package Sidebar

Install

npm i @locker/eslint-rule-maker

Weekly Downloads

3,633

Version

0.21.5

License

SEE LICENSE IN LICENSE.txt

Unpacked Size

29.4 kB

Total Files

7

Last publish

Collaborators

  • achabot
  • garychangsf
  • mjasso
  • caridy
  • jdalton
  • t.lau
  • dejang
  • rwaldron