eslint-plugin-roku
Version:
The ESLint custom plugin with rules and parser for .brs files
58 lines (57 loc) • 1.77 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
const bright_1 = require("@roku-road/bright");
const { name, version } = require('../package.json');
exports.version = version;
const warnings = [
'no-print',
'function-no-return',
'sub-to-function',
'no-shorthand-if',
'no-unused-params',
'function-no-return-type',
'function-name-camelcase',
];
const errors = [
'no-stop',
'no-uninitialized-variables',
'no-uninitialized-functions'
];
const allRules = [...warnings, ...errors].sort();
const makeRules = () => {
const mapped = {};
allRules.map(rule => (mapped[rule] = require(`./rules/${rule}`)));
return mapped;
};
const addRule = (level = 'warn', mapped = {}) => rule => (mapped[`roku/${rule}`] = level);
const ruleConfig = () => {
const mapped = {};
warnings.map(addRule('warn', mapped));
errors.map(addRule('error', mapped));
return mapped;
};
const rules = makeRules();
exports.rules = rules;
const parseForESLint = (code) => {
const result = bright_1.ast(code);
return {
ast: Object.assign({}, result, { comments: result.tokens
.filter(t => t.type.startsWith('COMMENT'))
.map(comment => {
return Object.assign({}, comment, { type: 'Line', value: comment.value.replace(/'|REM/i, '') });
}), tokens: result.tokens.filter(t => !t.type.startsWith('COMMENT') && t.type !== 'NEWLINE') }),
code,
scopeManager: null,
services: {},
visitorKeys: bright_1.visitorKeys,
};
};
exports.parseForESLint = parseForESLint;
const configs = {
recommended: {
parser: name,
plugins: ['roku'],
rules: ruleConfig(),
},
};
exports.configs = configs;