-
-
Notifications
You must be signed in to change notification settings - Fork 75
Indentation in decorators not working properly #438
Comments
+1 |
1 similar comment
+1 |
This persists through @connect(
(state: State) => ({
appBarVisible: state.ui.appBarVisible,
}),
)
class App extends React.Component<Props> { This should not throw an error; instead, ESLint reports:
This may or may not be related to broader issues I've noticed with the |
|
A custom rule will need to be created in the plugin to handle this. It would be fantastic if one of the people affected by this issue could contribute to it. As an aside, I am personally very against using a linter to validate formatting. IMO, formatting should be deterministic and automatic and I highly recommend giving Prettier a go if you haven't already. It is actually this parser which powers Prettier's TypeScript support! 😄 |
@JamesHenry do you mean to say that a rule like |
anyone was able to solve this somehow? |
Ok, folks, I've come up with modified 'use strict';
/**
* This rule filters out indent errors inside of decorators as original rule gives a lot of false positives
* Details: https://github.com/eslint/typescript-eslint-parser/issues/438
*/
const ruleComposer = require('eslint-rule-composer'),
eslint = require('eslint'),
indentRule = new eslint.Linter().getRules().get('indent'),
decoratorStartRegEx = /^@[a-zA-Z]+\(/;
module.exports = ruleComposer.filterReports(
indentRule,
(problem, metadata) => {
let codeString = '',
token = metadata.sourceCode.getTokenBefore(problem.node),
insideOfDecorator = false;
while (token && !insideOfDecorator) {
codeString = token.value + codeString;
insideOfDecorator = decoratorStartRegEx.test(codeString) && !codeString.includes(')');
token = metadata.sourceCode.getTokenBefore(token);
}
return !insideOfDecorator;
}
); you'll need to install that's it I'm not sure if this is a good candidate to add to typescript plugin, as it doesn't control indentation - just ignores it |
I think it should be fine to disable this rule; eslint should handle
linting code, not formatting.
I disabled the rule and use prettier or some similar alternative after
eslint to handle indentation.
…On Thu, 23 Aug 2018 at 17:39, Viktor Zozuliak ***@***.***> wrote:
anyone was able to solve this somehow?
—
You are receiving this because you are subscribed to this thread.
Reply to this email directly, view it on GitHub
<#438 (comment)>,
or mute the thread
<https://github.com/notifications/unsubscribe-auth/ABTy9vv5h4Vqzl95y7UF-c9stY_iM8Dsks5uTsy3gaJpZM4RvUrL>
.
|
@archseer this is a bit of misconception https://eslint.org/docs/about/ says
|
@zuzusik to each their own, I'd rather use eslint to catch problematic patterns than enforce indentation if git pre-commit hooks or https://editorconfig.org/ can do the same |
This issue has been migrated to the new project: typescript-eslint/typescript-eslint#9 Thanks! |
What version of TypeScript are you using?
2.6.2
What version of
typescript-eslint-parser
are you using?12.0.0
What code were you trying to parse?
What did you expect to happen?
No linting errors
What happened?
Got the following errors
The text was updated successfully, but these errors were encountered: