diff --git a/README.md b/README.md index 8e4fa81..367136b 100644 --- a/README.md +++ b/README.md @@ -137,7 +137,7 @@ When you use a regular expression `pattern`, you can also provide a `template` p ], "rules": { "header/header": [2, "block", [ - {"pattern": " Copyright \\d{4}", "template": " Copyright 2019"}, + {"pattern": " Copyright \\d{4}", "template": " Copyright 2019"}, "My Company" ]] } @@ -154,35 +154,56 @@ The rule works with both unix and windows line endings. For ESLint `--fix`, the ``` Possible values are `unix` for `\n` and `windows` for `\r\n` line endings. +### Vue support + +`eslint-plugin-header` now supports `.vue` files. Please see installation instructions for [eslint-plugin-vue](https://eslint.vuejs.org/user-guide/) before trying to integrate with `eslint-plugin-header`. There are some caveats to be aware of: +* ` +``` +--- +`"header/header": [2, "line", ["Copyright 2015", "My Company"]]` + +```vue + +``` +--- ## License diff --git a/lib/rules/header.js b/lib/rules/header.js index d4a609f..ea70de2 100644 --- a/lib/rules/header.js +++ b/lib/rules/header.js @@ -97,6 +97,9 @@ function getEOL(options) { } function hasHeader(src) { + if (src.substr(0, 8) === "", + options: ["line", "Copyright 2015, My Company"] + }, + { + code: "", + options: ["block", "*\n * Copyright 2015\n * My Company\n *"] + }, + { + code: "//Copyright (c) 2016, My Company\n", + options: ["line", "Copyright (c) 2016, My Company"] + }, + { + code: "//Copyright (c) 2016, My Company\n", + options: ["line", { + pattern: "Copyright \\(c\\) 2016, My Company", + template: "Copyright (c) 2016, My Company", + }] + }, ], invalid: [ { @@ -272,6 +294,33 @@ ruleTester.run("header", rule, { {message: "no newline after header"} ], output: "//Copyright 2020\n//My Company\n\nconsole.log(1);\n//Comment\nconsole.log(2);\n//Comment" - } + }, + { + code: "", + options: ["line", "Copyright 2015, My Company"], + errors: [ + {message: "missing header"} + ], + output: "" + }, + { + code: "", + options: ["block", "Copyright 2015, My Company"], + errors: [ + {message: "missing header"} + ], + output: "" + }, + { + code: "console.log(1);", + options: ["line", { + pattern: "Copyright \\(c\\) 2016, My Company", + template: "Copyright (c) 2016, My Company" + }], + errors: [ + {message: "missing header"} + ], + output: "//Copyright (c) 2016, My Company\nconsole.log(1);" + }, ] });