Skip to content

Commit

Permalink
feat(rule): improve error message
Browse files Browse the repository at this point in the history
  • Loading branch information
azu committed Jul 12, 2016
1 parent ea96887 commit 8120d6f
Show file tree
Hide file tree
Showing 4 changed files with 8 additions and 10 deletions.
5 changes: 4 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,10 @@ Add "simple-i18n-text" to your `.eslintrc`
{
"plugins": [
"simple-i18n-text"
]
],
"rules":{
"simple-i18n-text/no-raw-value": 2
}
}
```

Expand Down
2 changes: 1 addition & 1 deletion src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,6 @@ module.exports = {
"no-raw-value": require("./rules/no-raw-value")
},
rulesConfig: {
"no-raw-value": 2
"simple-i18n-text/no-raw-value": "on"
}
};
2 changes: 1 addition & 1 deletion src/rules/no-raw-value.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ const isStringLiteral = (node) => {
return node.type === "Literal" && typeof node.value === "string";
};
module.exports = function(context) {
const message = "The literal should be wrapped by `t()` or `pt()`.";
return {
JSXElement(node){
if (!node.children) {
Expand All @@ -15,6 +14,7 @@ module.exports = function(context) {
if (!value || value.length === 0) {
return;
}
const message = `"${value}" should be wrapped by t() or pt().`;
context.report({node: literal, message: message});
});
}
Expand Down
9 changes: 2 additions & 7 deletions test/no-raw-value-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,12 +19,7 @@ tester.run("no-raw-value", rule, {
invalid: [
{
code: `<p>NG</p>`,
errors: ["The literal should be wrapped by `t()` or `pt()`."],
parserOptions
},
{
code: "<p>`NG`</p>",
errors: ["The literal should be wrapped by `t()` or `pt()`."],
errors: [`"NG" should be wrapped by t() or pt().`],
parserOptions
}, {
code: `
Expand All @@ -35,7 +30,7 @@ class DetailButton extends React.Component {
</div>;
}
}`,
errors: ["The literal should be wrapped by `t()` or `pt()`."],
errors: [`"detail button" should be wrapped by t() or pt().`],
parserOptions
}
]
Expand Down

0 comments on commit 8120d6f

Please sign in to comment.