@feature-driven/eslint-plugin
Version:
📓 Lint feature-driven rules in full power
43 lines (36 loc) • 1.17 kB
JavaScript
/**
* @fileoverview Restrict allowed-list of project abstractions in src (app/features/pages/shared)
* @author Ilya Azin
*/
;
const model = require("./model");
/**
* @param {import("eslint").Rule.RuleContext} ctx
* @return {import("eslint").Rule.RuleListener}
*/
function create(ctx) {
// Unify path format
const filename = ctx.getFilename().replace(/\\/g, "/");
const code = ctx.getSourceCode();
/** @type {import("./types").Options} */
const options = { ...model.__default, ...(ctx.options[0] || {}) };
const isAllowed = options.include.some((pattern) => new RegExp(pattern).test(filename));
const isProhibited = options.exclude.some((pattern) => new RegExp(pattern).test(filename));
if (!isAllowed || isProhibited) {
ctx.report({
messageId: model.MESSAGES.INVALID,
loc: code.getLocFromIndex(0),
// TODO: split reporting later?
// data: {
// warning: "isn't allowed",
// },
// data: {
// warning: "is prohibited",
// },
});
}
return {};
}
module.exports = {
create,
};