File tree Expand file tree Collapse file tree 3 files changed +64
-1
lines changed Expand file tree Collapse file tree 3 files changed +64
-1
lines changed Original file line number Diff line number Diff line change 1+ const semver = require ( 'semver' )
2+ const stylelint = require ( 'stylelint' )
3+
4+ const ruleName = 'primer-css/TODO'
5+ const pattern = / \b T O D O @ ( [ ^ : ] + ) : \s + ( .+ ) $ /
6+
7+ const messages = stylelint . utils . ruleMessages ( ruleName , {
8+ rejected : message => message
9+ } )
10+
11+ module . exports = stylelint . createPlugin ( ruleName , ( enabled , options = { } ) => {
12+ const { currentVersion} = options
13+ if ( ! currentVersion ) {
14+ console . warn ( `No "currentVersion" supplied to ${ ruleName } ; bailing` )
15+ return ( ) => null
16+ }
17+
18+ let match
19+ return ( root , result ) => {
20+ root . walkComments ( node => {
21+ if ( ( match = node . text . match ( pattern ) ) ) {
22+ const [ substr , todoVersion , message ] = match
23+ if ( semver . lte ( todoVersion , currentVersion ) ) {
24+ stylelint . utils . report ( {
25+ message : messages . rejected ( `Unresolved TODO comment: "${ message } " (expected to be resolved in "${ todoVersion } ")` ) ,
26+ node,
27+ result,
28+ ruleName
29+ } )
30+ }
31+ }
32+ } )
33+ }
34+ } )
Original file line number Diff line number Diff line change 1+ #!/usr/bin/env node
2+ const stylelint = require ( 'stylelint' )
3+ const { red} = require ( 'colorette' )
4+
5+ const ruleName = 'primer-css/TODO'
6+ const cwd = process . cwd ( )
7+
8+ stylelint
9+ . lint ( { files : 'src/**/*.scss' } )
10+ . then ( data => {
11+ let fail = false
12+ for ( const { source, warnings} of data . results ) {
13+ if ( warnings . some ( w => w . rule === ruleName ) ) {
14+ console . warn ( '\n' + source . substr ( cwd . length + 1 ) )
15+ }
16+ for ( const warning of warnings ) {
17+ if ( warning . rule === ruleName ) {
18+ console . warn ( `${ red ( '✖' ) } ${ warning . text } ` )
19+ fail = true
20+ }
21+ }
22+ }
23+
24+ process . exit ( fail ? 1 : 0 )
25+ } )
Original file line number Diff line number Diff line change 1+ const currentVersion = process . env . PRIMER_VERSION || require ( './package.json' ) . version
2+
13module . exports = {
24 extends : [ 'stylelint-config-primer' ] ,
5+ plugins : [ './lib/stylelint-todo' ] ,
36 syntax : 'scss' ,
47 rules : {
5- 'primer/no-override' : false
8+ 'primer/no-override' : false ,
9+ 'primer-css/TODO' : [ true , { currentVersion, severity : 'error' } ]
610 }
711}
You can’t perform that action at this time.
0 commit comments