11// MIT © 2018 azu
22"use strict" ;
3- import { TxtNode , TxtNodeType , TxtParentNode , AnyTxtNode } from "@textlint/ast-node-types" ;
4- import { TextlintRuleError , TextlintRuleReportHandler } from "@textlint/types" ;
3+ import { AnyTxtNode , TxtNodeType } from "@textlint/ast-node-types" ;
4+ import { TextlintRuleContext , TextlintRuleError , TextlintRuleReportHandler } from "@textlint/types" ;
55import RuleHelper from "./textlint-rule-helper" ;
66import IgnoreNodeManager from "./IgnoreNodeManager" ;
77import { SourceLocation } from "./SourceLocation" ;
@@ -16,28 +16,25 @@ export interface wrapOptions {
1616 ignoreNodeTypes : TxtNodeType [ ]
1717}
1818
19- export function wrapReportHandler < T extends Function , R extends TextlintRuleReportHandler > (
19+ export function wrapReportHandler < T extends TextlintRuleContext , R extends TextlintRuleReportHandler > (
2020 options : wrapOptions ,
2121 context : T ,
2222 handler : (
23- report : ( node : AnyTxtNode , ruleError : TextlintRuleError ) => R
23+ report : ( node : AnyTxtNode , ruleError : TextlintRuleError ) => void
2424 ) => R
2525) {
2626 const ignoreNodeTypes = options . ignoreNodeTypes || [ ] ;
2727 const ignoreNodeManager = new IgnoreNodeManager ( ) ;
2828 const ruleHelper = new RuleHelper ( context ) ;
29- const text = ( context as any ) . getSource ( ) ;
29+ const text = context . getSource ( ) ;
3030 const sourceLocation = new SourceLocation ( text ) ;
31- const reportIfUnignored = function reportIfUnignored ( ...args : any [ ] ) : any | Promise < any > {
32- const node : TxtNode | TxtParentNode = args [ 0 ] ;
33- const ruleError : RuleErrorPadding = args [ 1 ] ;
34- const index = sourceLocation . toAbsoluteLocation ( node , ruleError ) ;
35- if ( ignoreNodeManager . isIgnoredIndex ( index ) ) {
36- return ;
37- }
38- return ( context as any ) . report ( ...args ) ;
31+ const reportIfUnignored = function reportIfUnignored ( node : AnyTxtNode , ruleError : TextlintRuleError ) : void | Promise < any > {
32+ const index = sourceLocation . toAbsoluteLocation ( node , ruleError ) ;
33+ if ( ignoreNodeManager . isIgnoredIndex ( index ) ) {
34+ return ;
3935 }
40- ;
36+ return context . report ( node , ruleError ) ;
37+ } ;
4138
4239 const handlers = handler ( reportIfUnignored ) ;
4340 Object . keys ( handlers ) . forEach ( nodeType => {
0 commit comments