@@ -54,7 +54,12 @@ function hasHeaderComment(program, context) {
5454 return vueHasHeaderComment ( program ) ;
5555 }
5656
57- const firstComments = context . sourceCode . getCommentsBefore ( program ) ;
57+ const firstProgramToken = context . sourceCode . getFirstToken ( program ) ;
58+ if ( ! firstProgramToken ) {
59+ return false ;
60+ }
61+
62+ const firstComments = context . sourceCode . getCommentsBefore ( firstProgramToken ) ;
5863 if ( firstComments . length === 0 ) {
5964 return false ;
6065 } else if (
@@ -241,40 +246,56 @@ module.exports = {
241246 trailingNewlinesMismatch : "Mismatched trailing newlines" ,
242247 } ,
243248 fixable : "code" ,
249+ defaultOptions : [
250+ { style : "jsdoc" , preservePragmas : true , enableVueSupport : false } ,
251+ ] ,
244252 schema : [
245253 {
246254 type : "object" ,
247255 properties : {
248256 source : {
257+ description : "The source of the header content." ,
249258 enum : [ "file" , "string" ] ,
250259 } ,
251260 style : {
261+ description :
262+ "The style to apply when formatting the header content." ,
252263 enum : [ "line" , "jsdoc" ] ,
253- default : "jsdoc" ,
254264 } ,
255265 content : {
266+ description : "The header content." ,
256267 type : "string" ,
257268 } ,
258269 path : {
270+ description : "The path to a file containing the header content." ,
259271 type : "string" ,
260272 } ,
261273 preservePragmas : {
274+ description :
275+ "The value indicating whether to preserve pragmas/directives in the leading comment." ,
262276 type : "boolean" ,
263- default : true ,
264277 } ,
265278 blockPrefix : {
279+ description : "The string prefixed to the header comment block." ,
266280 type : "string" ,
267281 } ,
268282 blockSuffix : {
283+ description : "The string suffixed to the header comment block." ,
269284 type : "string" ,
270285 } ,
271286 linePrefix : {
287+ description :
288+ "The string prefixed to each line of the header comment block." ,
272289 type : "string" ,
273290 } ,
274291 trailingNewlines : {
292+ description :
293+ "The number of validated newline characters which follow the header comment block." ,
275294 type : "number" ,
276295 } ,
277296 variables : {
297+ description :
298+ "A mapping of keys and values interpolated into the header comment block." ,
278299 type : "object" ,
279300 patternProperties : {
280301 "^.+$" : {
@@ -284,6 +305,8 @@ module.exports = {
284305 additionalProperties : false ,
285306 } ,
286307 patterns : {
308+ description :
309+ "A mapping of keys to regular expressions and default values to validate in the header comment block." ,
287310 type : "object" ,
288311 patternProperties : {
289312 "^\\w+$" : {
@@ -302,8 +325,9 @@ module.exports = {
302325 additionalProperties : false ,
303326 } ,
304327 enableVueSupport : {
328+ description :
329+ "A value indicating whether to enable support for linting .vue files." ,
305330 type : "boolean" ,
306- default : false ,
307331 } ,
308332 } ,
309333 required : [ "source" ] ,
@@ -419,16 +443,16 @@ module.exports = {
419443 return {
420444 Program : function ( node ) {
421445 if ( ! hasHeaderComment ( node , context ) ) {
422- const missingHeaderinsertionPoint = getMissingHeaderInsertionNode (
446+ const missingHeaderInsertionPoint = getMissingHeaderInsertionNode (
423447 context ,
424448 node ,
425449 ) ;
426450 context . report ( {
427- node : missingHeaderinsertionPoint ,
451+ node : missingHeaderInsertionPoint ,
428452 messageId : "missingHeader" ,
429453 fix : getFixerFn ( function ( fixer ) {
430454 return fixer . insertTextBefore (
431- missingHeaderinsertionPoint ,
455+ missingHeaderInsertionPoint ,
432456 appendNewlines (
433457 headerFormatter . format ( style ) ,
434458 sourceEol ,
0 commit comments