@@ -25,6 +25,8 @@ var decamelize = require('decamelize');
25
25
var sort = require ( 'vfile-sort' ) ;
26
26
var control = require ( 'remark-message-control' ) ;
27
27
var loadPlugin = require ( 'load-plugin' ) ;
28
+ var trough = require ( 'trough' ) ;
29
+ var wrapped = require ( 'wrapped' ) ;
28
30
var internals = require ( './rules' ) ;
29
31
30
32
/**
@@ -37,64 +39,32 @@ var internals = require('./rules');
37
39
* @param {string } id - Identifier.
38
40
* @param {Function } rule - Rule
39
41
* @param {* } options - Options for respective rule.
40
- * @return {Function } - See `attach` below .
42
+ * @return {Function } - Trough ware .
41
43
*/
42
- function attachFactory ( id , rule , options ) {
43
- /**
44
- * Attach the rule to a remark instance, unless `false`
45
- * is passed as an option.
46
- *
47
- * @return {Function? } - See `plugin` below.
48
- */
49
- function attach ( ) {
50
- /**
51
- * Attach the rule to a remark instance, unless `false`
52
- * is passed as an option.
53
- *
54
- * @param {Node } ast - Root node.
55
- * @param {File } [file] - Virtual file.
56
- * @param {Function } next - Signal end.
57
- */
58
- function plugin ( ast , file , next ) {
59
- var scope = file . namespace ( 'remark-lint' ) ;
60
-
61
- /*
62
- * Track new messages per file.
63
- */
64
-
65
- if ( scope . index === undefined || scope . index === null ) {
66
- scope . index = file . messages . length ;
67
- }
44
+ function ruleFactory ( id , rule , options ) {
45
+ var fn = wrapped ( rule ) ;
68
46
69
- /**
70
- * Add `ruleId` to each new message.
71
- *
72
- * @param {Error? } err - Optional failure.
73
- */
74
- function done ( err ) {
75
- var messages = file . messages ;
47
+ return function ( ast , file , next ) {
48
+ var scope = file . namespace ( 'remark-lint' ) ;
76
49
77
- while ( scope . index < messages . length ) {
78
- messages [ scope . index ] . ruleId = id ;
79
- messages [ scope . index ] . source = SOURCE ;
80
-
81
- scope . index ++ ;
82
- }
50
+ /* Track new messages per file. */
51
+ if ( scope . index === undefined || scope . index === null ) {
52
+ scope . index = file . messages . length ;
53
+ }
83
54
84
- next ( err ) ;
85
- }
55
+ fn ( ast , file , options , function ( err ) {
56
+ var messages = file . messages ;
86
57
87
- /*
88
- * Invoke `rule`, with `options`
89
- */
58
+ while ( scope . index < messages . length ) {
59
+ messages [ scope . index ] . ruleId = id ;
60
+ messages [ scope . index ] . source = SOURCE ;
90
61
91
- rule ( ast , file , options , done ) ;
92
- }
62
+ scope . index ++ ;
63
+ }
93
64
94
- return plugin ;
65
+ next ( err ) ;
66
+ } ) ;
95
67
}
96
-
97
- return attach ;
98
68
}
99
69
100
70
/**
@@ -180,6 +150,7 @@ function lint(remark, options) {
180
150
var enable = [ ] ;
181
151
var disable = [ ] ;
182
152
var known = [ ] ;
153
+ var pipeline = trough ( ) ;
183
154
var setting ;
184
155
var id ;
185
156
@@ -206,9 +177,19 @@ function lint(remark, options) {
206
177
}
207
178
}
208
179
209
- remark . use ( attachFactory ( id , rules [ id ] , setting ) ) ;
180
+ pipeline . use ( ruleFactory ( id , rules [ id ] , setting ) ) ;
210
181
}
211
182
183
+ /*
184
+ * Run all rules.
185
+ */
186
+
187
+ remark . use ( function ( ) {
188
+ return function ( node , file , next ) {
189
+ pipeline . run ( node , file , next ) ;
190
+ } ;
191
+ } ) ;
192
+
212
193
/*
213
194
* Allow comments to toggle messages.
214
195
*/
0 commit comments