ajafff / tslint-consistent-codestyle Goto Github PK
View Code? Open in Web Editor NEWCollection of awesome rules to extend TSLint
License: MIT License
Collection of awesome rules to extend TSLint
License: MIT License
Branch | Build failing 🚨 |
---|---|
Dependency | tsutils |
Current Version | 2.17.0 |
Type | dependency |
This version is covered by your current version range and after updating it in your project the build failed.
tsutils is a direct dependency of this project, and it is very likely causing it to break. If other packages depend on yours, this update is probably also breaking those in turn.
Bugfixes:
getControlFlowEnd
and endsControlFlow
(#22)
try
are filtered out if there is a catch
clausecatch
only end control flow if try
AND catch
definitely end control flowThere is a collection of frequently asked questions. If those don’t help, you can always ask the humans behind Greenkeeper.
Your Greenkeeper Bot 🌴
declare global { // should not produce an error
}
if (foo) { // shouldn't complain about braces here
label: while (true) {
}
}
Using tslint 5.2.0 and tslint-consistency-codestyle 1.2.0 and the attached tslint.json file (which uses just the example "naming-convention" rule found here: https://www.npmjs.com/package/tslint-consistent-codestyle).
Running the following:
tslint -c tslint.json 'src/**/*.ts'
Generates this error:
Am I missing some arguments?
Similar to tslint's no-parameter-reassignment
, but allows users to declare which parameter should be considered const:
function fn(/**@const*/ foo, bar) {
foo++; // error
bar++; // no error
}
Recognise /**@const*/
and /**@constant*/
The docs could really use some love.
naming-convention
docsPlease excuse if I've just done something silly...
I have the following tslint.json:
{
"defaultSeverity": "error",
"extends": "tslint:recommended",
"naming-convention": [
true,
{ "type": "default", "format": "camelCase", "leadingUnderscore": "forbid", "trailingUnderscore": "forbid" },
{ "type": "variable", "modifiers": ["global"], "format": "UPPER_CASE" },
{ "type": "variable", "modifiers": ["private", "protected" ], "format": "camelCase", "leadingUnderscore": "require", "trailingUnderscore": "forbid" },
{ "type": "parameter", "leadingUnderscore": "forbid", "trailingUnderscore": "forbid", "final": true },
{ "type": "member", "modifiers": ["private", "protected"], "leadingUnderscore": "require" },
{ "type": "type", "format": "PascalCase" },
{ "type": "interface", "prefix": "I" },
{ "type": "genericTypeParameter", "prefix": "T" },
{ "type": "enumMember", "format": "PascalCase" }
],
"jsRules": {},
"rules": {
"no-console": false,
"trailing-comma": false,
"no-unused-expression": false,
"no-empty": false,
"ordered-imports": false,
"one-variable-per-declaration": false,
"no-consecutive-blank-lines": true,
"no-bitwise": false
},
"rulesDirectory": [ "tslint-consistent-codestyle" ]
}
which I would expect should allow the following class declaration:
class Foo {
private _field: number = 0;
public get property(): number {
return this._field;
}
}
(in fact, this was the whole reason to install tslint-consistent-codestyle). Yet ./node_modules/.bin/tslint -p .
fails when run in the project folder, complaining about _field
(variable name must be in lowerCamelCase, PascalCase or UPPER_CASE)
I'd appreciate any pointers on what I'm doing wrong here (:
Enums that are exported or available in the global scope are ignored.
In https://github.com/ajafff/tslint-consistent-codestyle/blob/master/docs/prefer-const-enum.md, not sure why this restriction is in place?
Looking at the no-unused doc, I didn't expect to run into this warning. Using 1.5.0
, the following is an example of where I see a warning.
"no-unused": [
true,
"ignore-parameters"
]
// [tslint] Variable 'props' is unused. (no-unused)
const UsersList: React.SFC<Props> = ({ users, ...props }) => {};
I was wondering if you can add an option to always do early return. Thanks you.
May be we can have an option to allow destructuring before return?
const { data } = fetchSomething();
return data;
Something like this?
"no-var-before-return": [
true,
"allow-destructuring"
]
For a React import that needed only for JSX, no-unused
throws an error ERROR: src/app.tsx[1, 13]: Import 'React' is unused.
import * as React from 'react';
import * as ReactDom from 'react-dom';
ReactDom.render(<App />, document.getElementById('root'));
As a temporary workaround, we can set ignore-imports
to true.
Branch | Build failing 🚨 |
---|---|
Dependency |
tsutils
|
Current Version | 2.26.2 |
Type | dependency |
This version is covered by your current version range and after updating it in your project the build failed.
tsutils is a direct dependency of this project, and it is very likely causing it to break. If other packages depend on yours, this update is probably also breaking those in turn.
Features:
getIIFE
utilityThe new version differs by 5 commits.
2c8e48b
v2.27.0
139f75a
add getIIFE utility
3fcc6d8
chore(package): update @types/node to version 10.0.3 (#58)
66c1b12
fix devDependency version
a7034ba
fix build with [email protected]
See the full diff
There is a collection of frequently asked questions. If those don’t help, you can always ask the humans behind Greenkeeper.
Your Greenkeeper Bot 🌴
As requested by @CSchulz, make getter and setter configurable for naming convention.
Ideally this could also include type information, so we could force "is" or "has" as prefix for boolean accessors.
When extending a class, namingConventionRule should not complain about the names of overridden or implemented abstract methods and accessors.
To suppress compiler warnings for unused parameters and locals, you prefix the name with an underscore.
Many users don't want to allow leading underscores in their variable names globally. Of course you can restrict that to parameters, but that will still allow a leading underscore for used parameters.
The rule should support restricting the leading underscore to only parameters that are really unused.
This could be achieved by either using the type checker or making use of the upcoming functionality in tsutils
to track all uses of an identifier.
There are some fixed method names like toJSON
which is automatically called by JSON.stringify
, which don't follow the rules of CamelCase.
It would be nice to have the possibilty to define some exclusions for naming convention check.
Add new tsconfig.prod.json to build and publish without source maps.
Once typescript adds the ability to use literal typed constants as initializer in const enums, prefer-const-enum
should try to handle this as well.
Just a suggestion... similar to no-unused-variable
:
"no-unused": [true, {"ignore-pattern": "^_"}]
This allows you to use things like _
for array destructuring in parameters to skip no-unused for them.
let foo: Array<[string, boolean]> = [
['a', true],
['b', false],
];
Branch | Build failing 🚨 |
---|---|
Dependency | tsutils |
Current Version | 2.19.1 |
Type | dependency |
This version is covered by your current version range and after updating it in your project the build failed.
tsutils is a direct dependency of this project, and it is very likely causing it to break. If other packages depend on yours, this update is probably also breaking those in turn.
The new version differs by 4 commits.
4fe901d
v2.20.0
7ae4088
Add isThenableType and unionTypeParts
7e6d301
Update to [email protected] (#27)
67cc64b
chore(package): update mocha to version 5.0.0 (#26)
See the full diff
There is a collection of frequently asked questions. If those don’t help, you can always ask the humans behind Greenkeeper.
Your Greenkeeper Bot 🌴
Branch | Build failing 🚨 |
---|---|
Dependency |
tslib
|
Current Version | 1.9.0 |
Type | dependency |
This version is covered by your current version range and after updating it in your project the build failed.
tslib is a direct dependency of this project, and it is very likely causing it to break. If other packages depend on yours, this update is probably also breaking those in turn.
Updates __asyncValues
to more correctly align with CreateAsyncFromSyncIterator, and updates __asyncDelegator
to ensure throw
is correctly propagated.
There is a collection of frequently asked questions. If those don’t help, you can always ask the humans behind Greenkeeper.
Your Greenkeeper Bot 🌴
Firstly, this ruleset is fantastic and highly configurable, thanks so much for sharing it.
I think I may have found a small issue with the filter in 1.13.0. I can't be sure as I dont know how to check but I think it may be an issue with parsing the string into a regex. But maybe what I am trying to do isnt possible
I have this simple 2D Point class with public properties for the x,y coordinates initialized by a constructor param property:
export class Point implements IPoint {
constructor(public x: number = 0, public y: number = 0, public Selected: boolean = false) {}
}
I have configured tslint-consistent-codestyle
to enforce PascalCase as default, but I want to make an exception to this rule for the properties x
and y
to enforce camelCase using the filter option.
So in the example above, the Selected
property should be PascalCase while x and y should be fine to be camelCase.
My ruleset looks like this:
"naming-convention": [
true,
{"type": "default", "format": "PascalCase", "leadingUnderscore": "forbid", "trailingUnderscore": "forbid"},
{"type": "parameter", "format": "camelCase"},
{"type": "variable", "format": "camelCase"},
{"type": "property", "format": "camelCase"},
{"type": "property", "modifiers": ["public"], "format": "PascalCase"},
{"type": "parameterProperty", "filter": "^x$", "format": "camelCase"}
]
The last rule {"type": "parameterProperty", "filter": "^x$", "format": "camelCase"}
doesn't seem to be having any effect (i.e. Im still getting a tslint problem match for x and y), and in fact I cant seem to get the filter to work for anything including the examples in the docs, is this just me or is the filter not working?
I have this output during tslint.
Could not find implementations for the following rules specified in the configuration:
naming-covention
Try upgrading TSLint and/or ensuring that you have all necessary custom rules installed.
If TSLint was recently upgraded, you may have old rules configured which need to be cleaned up.
In my package.json:
"tslint": "^4.5.1",
"tslint-consistent-codestyle": "^0.2.2",
In tslint.json
{
"extends": "tslint:recommended",
"rulesDirectory": [
"node_modules/tslint-consistent-codestyle/rules"
],
"rules": {
"naming-convention": [
true,
{ "type": "member", "format": "camelCase" },
{ "type": "member", "modifiers": "protected", "leadingUnderscore": "require" },
{ "type": "member", "modifiers": "private", "prefix": "__" }
],
....
}
☝️ Greenkeeper’s updated Terms of Service will come into effect on April 6th, 2018.
Branch | Build failing 🚨 |
---|---|
Dependency | tsutils |
Current Version | 2.22.0 |
Type | dependency |
This version is covered by your current version range and after updating it in your project the build failed.
tsutils is a direct dependency of this project, and it is very likely causing it to break. If other packages depend on yours, this update is probably also breaking those in turn.
Bugfixes:
endsControlFlow
:
The new version differs by 3 commits.
fda575a
v2.22.1
b39884f
add tests for control flow analysis
685fa1d
control-flow: IterationStatement body is not guraranteed to be executed
See the full diff
There is a collection of frequently asked questions. If those don’t help, you can always ask the humans behind Greenkeeper.
Your Greenkeeper Bot 🌴
Here's my naming-convention
configuration:
"rules": {
"naming-convention": [ true,
{ "type": "default", "format": "camelCase" },
{ "type": "variable", "modifiers": "export", "format": "UPPER_CASE" },
{ "type": "function", "modifiers": "export", "format": "camelCase" }
]
}
As you can see from this, I want exported variables to be upper case, but exported functions to be camel case.
Here's some typical code that I'd write (it's ngrx-style code):
export const ACTION = "submit";
export const getValue = (state: State) => state.value;
This fails linting because getValue is expected to be upper case, but I'd prefer it to be camel case. I could write it like this:
export function getValue(state: State): boolean { return state.value; }
But it's a bit more verbose and (because of other linting rules I use) requires the function to have a type annotation.
Would it be possible to treat variables that are initialized with an arrow function to be treated as functions instead of variables?
I've taken a look at the rule, and it's simple enough to check if a variable is initialized to an arrow function:
if (declaration.initializer && declaration.initializer.kind === ts.SyntaxKind.ArrowFunction) {
this._checkName(declaration.name, TypeSelector.function, currentModifiers);
} else {
this._checkName(declaration.name, TypeSelector.variable, currentModifiers);
}
But I'm wondering if maybe it should be an option to make it behave this way so that it doesn't break everyone else's existing configurations.
var foo = {
fn() {console.log(foo);}
};
return foo;
Bug
v1.10.0
The no-else-after-return
rule seems to, by default, be issuing warnings when else if
's are used after return
statements.
The documentation for no-else-after-return
states that it "Works like no-else-return from eslint", and (at least for the current version of ESLint) the default behaviour of no-else-return
allows return
statements after else if
's.
When no-else-after-return: true
is specified, the following code causes an unnecessary else after return
warning to appear for me:
const val = Math.random();
if (val > 0.5) {
return 1;
} else if (val < 0.5) {
return -1;
}
return 0;
When no-else-after-return: true
is specified, the above code should not issue a warning.
If no-else-after-return: [true, { "allowElseIf": false }]
was specified, then the above code should issue a warning.
I use this rule as part of tslint-config-airbnb, which added no-else-after-return
to their ruleset in v5.4.1
.
Possible options:
"no-or"
to exempt if statements that have a logical OR in their condition"complexity": number
threshold similar to cyclomatic-complexity
File: ../blob/master/rules/noUnusedRule.ts
172 switch (parent.kind) {
180 case ts.SyntaxKind.BindingElement:
184 if (pattern.kind === ts.SyntaxKind.ObjectBindingPattern &&
The condition in line 184 never true.
Example:
@Effect()effect onSetStep = this.action$
.ofType<SwitchAction>(SwitchAction.TYPE)
.withLatestFrom(this.stepbarService.stepbar$)
.map(([_action, stepbar]) => { // the _action-Variable is correctly prefixed but marked by the lint
return new Action(stepbar.item);
});
Hi,
We have an error when we install tslint-consistent-codestyle v1.7. The dependency tsutils 2.11.0 doesn't exist.
Can you patch your package.json ?
Allow an array of formats to be specified. They are not merged when extending but overridden.
Should be easy to implement.
Some things to consider:
function f() {
var a = foo(), b = bar(a, a);
return b;
}
function f() {
var a = foo();
return bar(a, a);
}
function f() {
var a: {} = "foo"; // move annotation to funtion signature, iff this is the only return
return a;
}
function f(): {} {
return "foo";
}
What do you think of adding a new selector to the naming-convention rule which applies to variables that are containing a construct signature?
With the current selectors I cannot target my redux connected components which has to be written in PascalCase, while keeping non-class containing variables in camelCase.
Config:
{"type": "variable", "format": ["camelCase"]}
Code:
// connect returns a react component class
const PascalCaseComponent1 = connect(..)(SomeComponent);
const camelCaseComponent2 = connect(..)(SomeComponent);
Result:
PascalCaseComponent1: variable name must be in camelCase
Config:
{"type": "variable", "format": ["camelCase"]}
{"type": "constructorVariable", "format": ["PascalCase"]}
Code:
// connect returns a react component class
const PascalCaseComponent1 = connect(..)(SomeComponent);
const camelCaseComponent2 = connect(..)(SomeComponent);
Result:
camelCaseComponent2: variable name must be in PascalCase
Question for you (maybe a bug?) regarding no-unused
and callback args. If I need to use a callback arg which is somewhere towards the right side of the list of args, but I don't need to use some of the preceding args, should that be an error?
Here's a screenshot of some code I'm working with, using rewriters
in winston 2.x.
I don't think I can use placeholders to ignore elements like we could with array destructuring.
Ref: palantir/tslint#3800
how can i turn off this rule below ?
// interface names must start with "I". The following part of the name must be valid PascalCase
{
"type": "interfaceq",
"prefix": "I",
},
You can suppress compiler warnings for unused parameters by prefixing the name with an underscore. tslint allows the same for variables.
But variables are only necessary to keep around when they are used in an object destructuring containing rest. Parameters only need to be specified when they are followed by at least one actually used parameter.
Add a new rule that warns for all identifiers that are not strictly necessary even if they are allowed to exist because of some prefix.
Hello,
first of all - thanks for great linter.
I have such variables in my code:
articleID,
addUIPart,
isCKELoaded
and so on,
I would like to keep this rule on but with some excludes, is it possible?
same with methods
Branch | Build failing 🚨 |
---|---|
Dependency | tslib |
Current Version | 1.8.1 |
Type | dependency |
This version is covered by your current version range and after updating it in your project the build failed.
tslib is a direct dependency of this project, and it is very likely causing it to break. If other packages depend on yours, this update is probably also breaking those in turn.
This release introduces import helpers that are utilized by TypeScript 2.7's --esModuleInterop
flag for interoperability between ECMAScript modules and legacy module formats.
The new version differs by 4 commits.
3d0f4d4
Update version to '1.9.0'.
c380b8d
Merge pull request #43 from Microsoft/import-helpers
c1cd8e1
Remove erroneous semicolons from import star helper
b630cee
Add import helpers
See the full diff
There is a collection of frequently asked questions. If those don’t help, you can always ask the humans behind Greenkeeper.
Your Greenkeeper Bot 🌴
From the documentation page of the "no-unused" rule, it says:
Does not check private class members.
But considering this snippet:
export class Test {
private aaaa = 'c';
bbbb: string;
public cccc: string;
constructor(private dddd, public eeee) { }
}
it does not mark any of the members as unused.
Is this intentional or a bug?
If intentional, is this planned as an extension or is there a specific reason to stay with it?
Sorry in advance for what might be an unhelpful report. I somehow wrote some code that causes the no-unnecessary-type-annotation
rule to get stuck in an infinite loop inside removeSignatureReturn
. It is getting passed the string '<A extends Action>(action: A): A'
, which appears to come from the redux type definitions. The function seems to assume the first char will be (
, but in my case it is <
. Fixing that localized issue is easy, but I have no idea what broader conditions caused that to happen, or how you'd write a test for it.
(function (param: string) {}(''));
// is equal to
(function (param: string) {})('');
Both expressions should be recognized as IFFE, therefore the parameter type annotation is unnecessary.
Currently only one (the latter?) is correctly detected.
[email protected] allows omitting the catch binding. Therefore no-unused
should no longer treat this kind of declaration special (when using ts@>=2.5.0). If it's unused, you can just remove it.
Also add a flag to restore the old behavior and ignore catch bindings completely.
To me, it feels unconventional to use return in a constructor and it can potentially override the object reference if a non-primitive type is returned. I like the early-exit
rule, but would love be able to enable an option that would disable the rule inside all constructors.
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.