11'use strict' ;
22
3+ import { LINT_MESSAGES } from '../constants.mjs' ;
34import createLinterEngine from './engine.mjs' ;
45import reporters from './reporters/index.mjs' ;
56import rules from './rules/index.mjs' ;
@@ -22,6 +23,13 @@ const createLinter = (dryRun, disabledRules) => {
2223 . map ( ( [ , rule ] ) => rule ) ;
2324 } ;
2425
26+ /**
27+ * @type {import('./types').LintDeclarations }
28+ */
29+ const declarations = {
30+ skipDeprecation : [ ] ,
31+ } ;
32+
2533 const engine = createLinterEngine ( getEnabledRules ( disabledRules ) ) ;
2634
2735 /**
@@ -37,7 +45,7 @@ const createLinter = (dryRun, disabledRules) => {
3745 * @param entries
3846 */
3947 const lintAll = entries => {
40- issues . push ( ...engine . lintAll ( entries ) ) ;
48+ issues . push ( ...engine . lintAll ( entries , declarations ) ) ;
4149 } ;
4250
4351 /**
@@ -58,6 +66,87 @@ const createLinter = (dryRun, disabledRules) => {
5866 }
5967 } ;
6068
69+ /**
70+ * Parse an inline-declaration found in the markdown input
71+ *
72+ * @param {string } declaration
73+ */
74+ const parseLinterDeclaration = declaration => {
75+ // Trim off any excess spaces from the beginning & end
76+ declaration = declaration . trim ( ) ;
77+
78+ // Extract the name for the declaration
79+ const [ name , ...value ] = declaration . split ( ' ' ) ;
80+
81+ switch ( name ) {
82+ case 'skip-deprecation' : {
83+ if ( value . length !== 1 ) {
84+ issues . push ( {
85+ level : 'error' ,
86+ location : {
87+ // TODO,
88+ path : '' ,
89+ position : 0 ,
90+ } ,
91+ message : LINT_MESSAGES . malformedLinterDeclaration . replace (
92+ '{{message}}' ,
93+ `Expected 1 argument, got ${ value . length } `
94+ ) ,
95+ } ) ;
96+
97+ break ;
98+ }
99+
100+ // Get the deprecation code. This should be something like DEP0001.
101+ const deprecation = value [ 0 ] ;
102+
103+ // Extract the number from the code
104+ const deprecationCode = Number ( deprecation . substring ( 'DEP' . length ) ) ;
105+
106+ // Make sure this is a valid deprecation code, output an error otherwise
107+ if (
108+ deprecation . length !== 7 ||
109+ ! deprecation . startsWith ( 'DEP' ) ||
110+ isNaN ( deprecationCode )
111+ ) {
112+ issues . push ( {
113+ level : 'error' ,
114+ location : {
115+ // TODO,
116+ path : '' ,
117+ position : 0 ,
118+ } ,
119+ message : LINT_MESSAGES . malformedLinterDeclaration . replace (
120+ '{{message}}' ,
121+ `Invalid deprecation code ${ deprecation } `
122+ ) ,
123+ } ) ;
124+
125+ break ;
126+ }
127+
128+ declarations . skipDeprecation . push ( deprecationCode ) ;
129+
130+ break ;
131+ }
132+ default : {
133+ issues . push ( {
134+ level : 'error' ,
135+ location : {
136+ // TODO
137+ path : '' ,
138+ position : 0 ,
139+ } ,
140+ message : LINT_MESSAGES . invalidLinterDeclaration . replace (
141+ '{{declaration}}' ,
142+ name
143+ ) ,
144+ } ) ;
145+ break ;
146+ }
147+ }
148+ } ;
149+
61150 /**
62151 * Checks if any error-level issues were found during linting
63152 *
@@ -70,6 +159,7 @@ const createLinter = (dryRun, disabledRules) => {
70159 return {
71160 lintAll,
72161 report,
162+ parseLinterDeclaration,
73163 hasError,
74164 } ;
75165} ;
0 commit comments