-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #10 from kyaido/option_message
Add custom message option
- Loading branch information
Showing
9 changed files
with
131 additions
and
65 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
module.exports = { | ||
env: { | ||
es6: true, | ||
node: true, | ||
}, | ||
extends: ['eslint:recommended', 'prettier'], | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
{ | ||
"singleQuote": true | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,5 @@ | ||
'use strict'; | ||
|
||
module.exports.rules = { | ||
'literal-blacklist': require('./rules/literal-blacklist.js') | ||
}; | ||
'literal-blacklist': require('./rules/literal-blacklist.js'), | ||
}; |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,29 +1,56 @@ | ||
'use strict'; | ||
|
||
module.exports = function(context) { | ||
module.exports = { | ||
meta: { | ||
schema: [ | ||
{ | ||
type: 'array', | ||
items: { | ||
oneOf: [ | ||
{ | ||
type: 'string', | ||
}, | ||
{ | ||
type: 'object', | ||
properties: { | ||
term: { | ||
type: 'string', | ||
}, | ||
message: { | ||
type: 'string', | ||
}, | ||
}, | ||
additionalProperties: false, | ||
}, | ||
], | ||
}, | ||
uniqueItems: true, | ||
}, | ||
], | ||
}, | ||
|
||
let options = []; | ||
if (Array.isArray(context.options[0])) { | ||
options = context.options[0]; | ||
} | ||
create: (context) => { | ||
let options = []; | ||
if (Array.isArray(context.options[0])) { | ||
options = context.options[0]; | ||
} | ||
|
||
return { | ||
'Literal': node => { | ||
let message = null; | ||
let value = String(node.value); | ||
return { | ||
Literal: (node) => { | ||
const value = String(node.value); | ||
|
||
options.forEach(option => { | ||
if(value.indexOf(option) !== -1) { | ||
message = `You should not use "${option}".`; | ||
context.report({node: node, message: message}); | ||
} | ||
}); | ||
} | ||
}; | ||
}; | ||
options.forEach((option) => { | ||
const isStringOption = typeof option === 'string'; | ||
const term = isStringOption ? option : option.term; | ||
|
||
module.exports.schema = [{ | ||
type: 'array', | ||
items: { type: 'string' }, | ||
uniqueItems: true | ||
}]; | ||
if (value.indexOf(term) !== -1) { | ||
const message = isStringOption | ||
? `You should not use '${term}'.` | ||
: option.message; | ||
context.report({ node, message }); | ||
} | ||
}); | ||
}, | ||
}; | ||
}, | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters