Skip to content

Consider @typescript-eslint's rules for invalid messages #101

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Apr 23, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions src/postprocess.js
Original file line number Diff line number Diff line change
Expand Up @@ -92,12 +92,14 @@ const get_identifier = str => (str && str.match(/^[^\s!"#%&\\'()*+,\-./:;<=>?@[\
const is_valid_message = (block, message, translation) => {
switch (message.ruleId) {
case 'eol-last': return false;
case '@typescript-eslint/indent':
case 'indent': return !translation.options.template;
case 'linebreak-style': return message.line !== translation.end;
case 'no-labels': return get_identifier(get_referenced_string(block, message)) !== '$';
case 'no-restricted-syntax': return message.nodeType !== 'LabeledStatement' || get_identifier(get_referenced_string(block, message)) !== '$';
case 'no-self-assign': return !state.var_names.has(get_identifier(get_referenced_string(block, message)));
case 'no-unused-labels': return get_referenced_string(block, message) !== '$';
case '@typescript-eslint/quotes':
case 'quotes': return !translation.options.in_quoted_attribute;
}
return true;
Expand Down
11 changes: 11 additions & 0 deletions test/samples/typescript-indentation/.eslintrc.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
module.exports = {
parser: '@typescript-eslint/parser',
plugins: [
'@typescript-eslint',
],
rules: {
indent: 'off',
'@typescript-eslint/indent': ['error', 'tab'],
semi: 'error',
},
};
6 changes: 6 additions & 0 deletions test/samples/typescript-indentation/Input.svelte
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
<script lang='ts'>
let foo
let bar
</script>

<div>{foo}</div>
31 changes: 31 additions & 0 deletions test/samples/typescript-indentation/expected.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
[
{
"ruleId": "semi",
"line": 2,
"column": 9,
"fix": {
"range": [27, 27],
"text": ";"
}
},
{
"ruleId": "@typescript-eslint/indent",
"line": 3,
"column": 2,
"endLine": 3,
"endColumn": 3,
"fix": {
"range": [29, 30],
"text": ""
}
},
{
"ruleId": "semi",
"line": 3,
"column": 10,
"fix": {
"range": [37, 37],
"text": ";"
}
}
]
10 changes: 10 additions & 0 deletions test/samples/typescript-template-quotes/.eslintrc.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
module.exports = {
parser: '@typescript-eslint/parser',
plugins: [
'@typescript-eslint',
],
rules: {
quotes: 'off',
'@typescript-eslint/quotes': ['error', 'single']
},
};
4 changes: 4 additions & 0 deletions test/samples/typescript-template-quotes/Input.svelte
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
{'foo'}
{"bar"}
<div class={"baz1"}></div>
<div class='{"baz2"}'></div>
24 changes: 24 additions & 0 deletions test/samples/typescript-template-quotes/expected.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
[
{
"ruleId": "@typescript-eslint/quotes",
"line": 2,
"column": 2,
"endLine": 2,
"endColumn": 7,
"fix": {
"range": [9, 14],
"text": "'bar'"
}
},
{
"ruleId": "@typescript-eslint/quotes",
"line": 3,
"column": 13,
"endLine": 3,
"endColumn": 19,
"fix": {
"range": [28, 34],
"text": "'baz1'"
}
}
]