Eslint

AST

EsLint rule = f(AST)

module.exports = {
  context(context) {
    return {
      DebuggerStatement() {
        context.report("Не коміть це!")
      }
    }
  }
}

Як написати своє правило 

  • Вкинути поганий кусок коду AST explorer
  • Виявити селектор
  • Вигадати образливу фразу, щоб програміст це не використовував
  • Написати код
  • Ви прекрасні
  • А може й ні, це не по лінтер правилу це визначається

Можна щось запілити

module.exports = {
    configs: {
        base: {
            root: true,
            plugins: ['social-tech'],
            parser: require.resolve('vue-eslint-parser'),
            parserOptions: {
                ecmaVersion: 2015,
                sourceType: 'module',
                ecmaFeatures: {
                    jsx: true,
                    experimentalObjectRestSpread: true,
                }
            },
            env: {
                browser: true,
                es6: true,
            },
            rules: {
                'social-tech/some-rule-name': 'error',
            },
        },
    },
    rules: {
        'some-rule-name': require('./rule-file'),
    },
}
module.exports = {
    meta: {
        docs: {
            description: 'some description',
        },
        fixable: null, // "code", "whitespace"
        schema: []
    },
    create(context) {}
}

Eslint

By Kolya Koval

Eslint

  • 311