UNPKG

@maniascript/mslint

Version:
25 lines (24 loc) 793 B
import {} from '../linter/rule.js'; import { IncludeDirective } from '@maniascript/parser'; export const includeOneTime = { meta: { id: 'include-one-time', description: 'Check that a file is not included several times', recommended: true }, create(context) { const alreadyIncluded = new Set(); return { 'IncludeDirective:exit': (node) => { if (node instanceof IncludeDirective) { if (alreadyIncluded.has(node.path.value)) { context.report(node.path, 'This file is already included'); } else { alreadyIncluded.add(node.path.value); } } } }; } };