Skip to content

Commit

Permalink
#9: Either template or templateFile must be set
Browse files Browse the repository at this point in the history
 - Simply return null, which disables the fixer in createFixer
 - Also updated all the years in the snapshot tests
  • Loading branch information
nickdeis committed Feb 24, 2019
1 parent 8f28ee1 commit 7e1946a
Show file tree
Hide file tree
Showing 5 changed files with 18 additions and 9 deletions.
2 changes: 1 addition & 1 deletion tests/lib/rules/fix-result-1.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/**
* Copyright (c) 2018, Nick Deis
* Copyright (c) 2019, Nick Deis
*/


Expand Down
2 changes: 1 addition & 1 deletion tests/lib/rules/fix-result-2.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/**
* Copyright (c) 2018, Nick Deis
* Copyright (c) 2019, Nick Deis
*/


Expand Down
2 changes: 1 addition & 1 deletion tests/lib/rules/fix-result-3.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@

/**
* Copyright (c) 2018, Nick Deis
* Copyright (c) 2019, Nick Deis
*/


Expand Down
16 changes: 13 additions & 3 deletions tests/lib/rules/notice.js
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,12 @@ function noStyle(){
}
`;

const noStyle2 = `
function noStyle2(){
return "I didn't read the style guide :(";
}
`;

const testCode4 = fs.readFileSync(__dirname + "/test-case-4.js", "utf8");

const testCase4 = {
Expand Down Expand Up @@ -85,10 +91,14 @@ ruleTester.run("notice", rule, {
//test configurable messages
{
code: noStyle,
options: [{ mustMatch, template, messages:{whenFailedToMatch:"Custom message"} }],
options: [{ mustMatch, template, messages: { whenFailedToMatch: "Custom message" } }],
errors: [{ message: "Custom message" }],
output: fs.readFileSync(__dirname + "/fix-result-1.js", "utf8")
}
output: fs.readFileSync(__dirname + "/fix-result-1.js", "utf8")
},
/**
* Test the case where no template file is set, should COULD_NOT_FIND error with no autofixes suggested
*/
{ code: noStyle2, options: [{ mustMatch }], errors: [{ message: COULD_NOT_FIND }], output: null }
],
valid: [
{
Expand Down
5 changes: 2 additions & 3 deletions utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -37,9 +37,8 @@ function regexpizeTemplate({ template, varRegexps }) {

function resolveTemplate({ templateFile, template, fileName }) {
if (template) return template;
if (!templateFile) {
throw new Error(`Either template or templateFile must be set`);
}
//No template file, so move foward and disable --fix
if (!templateFile) return null;
//Naively look for the templateFile first
if (fs.existsSync(templateFile)) {
return fs.readFileSync(templateFile, "utf8");
Expand Down

0 comments on commit 7e1946a

Please sign in to comment.