export default async function errorhandler(ctx: Context, next: () => Promise<any>) {
try {
await next();
} catch (err) {
// some code here
}
}
with tslint.json configuration:
{
"extends": "tslint:recommended",
"rules": {
"arrow-parens": false,
"indent": [true, "spaces", 2],
"interface-name": [false],
"member-access": [true, "no-public"],
"no-require-imports": false,
"no-switch-case-fall-through": true,
"no-unused-variable": false,
"quotemark": [true, "single"],
"switch-default": true,
"object-literal-sort-keys": false
}
}
I was trying to configure vscode-tslint to show exact warnings for VS Code as tslint CLI does. It says:
Since tslint version 5 the rule no-unused-variable rule requires type information
So I changed no-unused-variable to false and also changed tsconfig.json noUnusedLocals and noUnusedParameters to true.
With this configuration
If I change ctx to _ctx as some people advice.
variable-name rule which expects _ctx to not start with underscoreIt looks like there's no way to make tslint/tsc work properly without ignoring first line with tslint:ignore. Or maybe I'm wrong?
"variable-name": { "options": { "check-format": ["allow-leading-underscore"] } }
https://palantir.github.io/tslint/rules/variable-name/
I do admit this is unintuitive and should probably be fixed in the recommended config for the next major version.
Well yes, but for me avoiding variable names like _ctx seems reasonable. From my perspective this seems more like a misleading behaviour of TS compiler. In my opinion it should not complain of first argument which is not used if second argument is used 🤷♂️
"variable-name": { "options": { "check-format": ["allow-leading-underscore"] } }https://palantir.github.io/tslint/rules/variable-name/
I do admit this is unintuitive and should probably be fixed in the recommended config for the next major version.
Correct rule is now "variable-name": {
"options": "allow-leading-underscore"
},
I believe we should close this in favor of #3442. As mentioned in that issue, allow-leading-underscore does not differentiate between unused function arguments and other variable names that start with underscore.
Changing the recommended setting to allow all variables to start with underscore is a considerably larger change compared to only allowing underscores on function arguments.
Agreed, thanks for pointing that out @aryzing.
Most helpful comment
Well yes, but for me avoiding variable names like
_ctxseems reasonable. From my perspective this seems more like a misleading behaviour of TS compiler. In my opinion it should not complain of first argument which is not used if second argument is used 🤷♂️