Skip to content

Commit

Permalink
fix(wrap): fix arguments order
Browse files Browse the repository at this point in the history
  • Loading branch information
azu committed Jan 3, 2019
1 parent b107ad4 commit f1219db
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 15 deletions.
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -145,9 +145,9 @@ Example: ignore `BlockQuote` and `Code` node.
import { wrapReportHandler } from "textlint-rule-helper";
const reporter = function (context) {
const { Syntax, getSource } = context;
return wrapReportHandler({
return wrapReportHandler(context, {
ignoreNodeTypes: [Syntax.BlockQuote, Syntax.Code]
}, context, report => { // <= wrap version of context.report
},report => { // <= wrap version of context.report
// handler should return a rule handler object
return {
[Syntax.Paragraph](node) {
Expand Down
8 changes: 3 additions & 5 deletions src/wrap-report-handler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,16 +17,14 @@ export interface wrapReportHandlerOptions {

/**
*
* @param options
* @param context
* @param options
* @param handler
*/
export function wrapReportHandler<T extends Readonly<TextlintRuleContext>, R extends TextlintRuleReportHandler>(
options: wrapReportHandlerOptions,
context: T,
handler: (
report: (node: AnyTxtNode, ruleError: TextlintRuleError) => void
) => R
options: wrapReportHandlerOptions,
handler: (report: (node: AnyTxtNode, ruleError: TextlintRuleError) => void) => R
) {
const ignoreNodeTypes = options.ignoreNodeTypes || [];
const ignoreNodeManager = new IgnoreNodeManager();
Expand Down
16 changes: 8 additions & 8 deletions test/wrap-report-handler-test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,9 @@ describe("wrapReportHandler", function () {
textlint.setupRules({
"rule-key": function (context) {
const { RuleError } = context;
return wrapReportHandler({
return wrapReportHandler(context, {
ignoreNodeTypes: Object.keys(ASTNodeTypes).concat("my-type")
}, context, report => {
}, report => {
return {
...(Object.keys(ASTNodeTypes).reduce((object, key) => {
object[key] = (node: AnyTxtNode) => {
Expand Down Expand Up @@ -65,9 +65,9 @@ code
let isCalled = false;
textlint.setupRules({
"rule-key": function (context: any) {
return wrapReportHandler({
return wrapReportHandler(context, {
ignoreNodeTypes: [context.Syntax.BlockQuote, context.Syntax.Code]
}, context, _report => {
}, _report => {
return {
[context.Syntax.Paragraph]() {
isCalled = true
Expand Down Expand Up @@ -126,9 +126,9 @@ code
textlint.setupRules({
"rule-key": function (context) {
const { Syntax, getSource } = context;
return wrapReportHandler({
return wrapReportHandler(context, {
ignoreNodeTypes: [context.Syntax.Code]
}, context, report => {
}, report => {
return {
[Syntax.Paragraph](node) {
const text = getSource(node);
Expand Down Expand Up @@ -161,9 +161,9 @@ code
textlint.setupRules({
"rule-key": function (context) {
const { Syntax, RuleError } = context;
return wrapReportHandler({
return wrapReportHandler(context, {
ignoreNodeTypes: [context.Syntax.Code]
}, context, report => {
}, report => {
return {
[Syntax.Paragraph](node) {
const text = context.getSource(node);
Expand Down

0 comments on commit f1219db

Please sign in to comment.