Skip to content
This repository has been archived by the owner on Mar 25, 2021. It is now read-only.

Rule file-header should have an option to allow // comments #3180

Closed
dileepkeeppalli opened this issue Aug 29, 2017 · 3 comments · Fixed by #4560
Closed

Rule file-header should have an option to allow // comments #3180

dileepkeeppalli opened this issue Aug 29, 2017 · 3 comments · Fixed by #4560

Comments

@dileepkeeppalli
Copy link

dileepkeeppalli commented Aug 29, 2017

Rule file-header is not working. Even if particular header in a file like Copyright \d{4} didn't add in the file or any wrong text adds, No Lint errors are getting.

  • TSLint version: ~5.3.2
  • TypeScript version: ~2.3.3
  • Running TSLint via: angular CLI

TypeScript code being linted

"file-header": [
    true,
    "Copyright \\d{4}"
  ]

with tslint.json configuration: tried in 2 different ways

{
  "rulesDirectory": [
    "node_modules/codelyzer"
  ],
  "rules": {
   // lint
  },
  "file-header": [
    true,
    "Copyright \\d{4}"
  ]
}
{
  "rulesDirectory": [
    "node_modules/codelyzer"
  ],
  "rules": {
   // lint,
   "file-header": [
    true,
    "Copyright \\d{4}"
  ]
  },
  
}

Actual behavior

TS lint is not validating wheather the header text is present or not present

Expected behavior

TSLint is failing to validate the file header text

@IllusionMH
Copy link
Contributor

@dileepkeeppalli is there a chance that you have BOM in your files?

@atifsyedali
Copy link

atifsyedali commented Dec 12, 2017

This is now broken for me too. It used to work.

I think this is due to #2525 which used to check if the given text was present in the entire file text range, but now only checks the first comment in the file.

For example, the header in the file may look like this...

// **********************************
// Copyright 2017 Company
// **********************************

And the first comment it parses is // **********************************, which does not match the regular expression that expects a multiline header.

However, the following works though, because a multi-line comment is just one comment:

/***********************************
 * Copyright 2017 Company
 ***********************************/

@JoshuaKGoldberg
Copy link
Contributor

JoshuaKGoldberg commented Nov 4, 2018

Sounds like the rule could be given an option to consider consecutive // comments as one long file header. We can take that as a PR; modifying issue title to make this more discoverable.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants