|
| 1 | +// no identifiers used for bindings that are unknown |
| 2 | + |
| 3 | +import * as ast from "../grammar/ast"; |
| 4 | +import { Diagnostic } from ".."; |
| 5 | +import { getRuleConfig } from "../config/util"; |
| 6 | +import { createDiagnosticsFactory } from "../diagnostic"; |
| 7 | +import { RuleFactory } from "../linting-rule"; |
| 8 | +import { isInOutKeyword, isOutEvent, isOutKeyword } from "../util"; |
| 9 | + |
| 10 | +export const outParamInOutEvent = createDiagnosticsFactory(); |
| 11 | + |
| 12 | +export const no_out_params_in_out_events: RuleFactory = factoryContext => { |
| 13 | + const config = getRuleConfig("no_out_params_in_out_events", factoryContext.userConfig); |
| 14 | + |
| 15 | + if (config.isEnabled) { |
| 16 | + factoryContext.registerRule<ast.Event>(ast.SyntaxKind.Event, (node, context) => { |
| 17 | + const diagnostics: Diagnostic[] = []; |
| 18 | + |
| 19 | + if (isOutEvent(node)) { |
| 20 | + for (const param of node.parameters) { |
| 21 | + if (param.direction && isOutKeyword(param.direction)) { |
| 22 | + diagnostics.push( |
| 23 | + outParamInOutEvent( |
| 24 | + config.severity, |
| 25 | + "Not allowed to use 'out' parameters in out events, use 'in' instead", |
| 26 | + context.source, |
| 27 | + param.direction.position |
| 28 | + ) |
| 29 | + ); |
| 30 | + } |
| 31 | + if (param.direction && isInOutKeyword(param.direction)) { |
| 32 | + diagnostics.push( |
| 33 | + outParamInOutEvent( |
| 34 | + config.severity, |
| 35 | + "Not allowed to use 'inout' parameters in out events, use 'in' instead", |
| 36 | + context.source, |
| 37 | + param.direction.position |
| 38 | + ) |
| 39 | + ); |
| 40 | + } |
| 41 | + } |
| 42 | + } |
| 43 | + |
| 44 | + return diagnostics; |
| 45 | + }); |
| 46 | + } |
| 47 | +}; |
| 48 | + |
| 49 | +export default no_out_params_in_out_events; |
0 commit comments