-
Notifications
You must be signed in to change notification settings - Fork 15
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
no-flag-args rule for class properties declaration in constructor #69
Comments
🤔Yes, I think this is correct and it should show an error. The description for
In your case, the Consider the following: Beforeexport class MyModel {
constructor(public isBoxAvailable = false, public isCertAvailable = false) {}
}
// 4 cases:
new MyModel(false, false);
new MyModel(true, false);
new MyModel(false, true);
new MyModel(true, true); After// isBoxAvailable = undefined, isCertAvailable = undefined
export abstract class MyModel {
abstract private methodUsingBoxAvailableValue();
abstract private methodUsingCertAvailableValue();
}
// isBoxAvailable = false, isCertAvailable = false
export class MyModelWithoutBoxAvailableAndWithoutCertAvailable extends MyModel {
private methodUsingBoxAvailableValue() {
// do something assuming box available is false.
}
private methodUsingCertAvailableValue() {
// do something assuming box available is false.
}
}
// isBoxAvailable = true, isCertAvailable = false
export class MyModelWithBoxAvailableAndWithoutCertAvailable extends MyModel {
private methodUsingBoxAvailableValue() {
// do something assuming box available is true.
}
private methodUsingCertAvailableValue() {
// do something assuming box available is false.
}
}
// isBoxAvailable = false, isCertAvailable = true
export class MyModelWithoutBoxAvailableAndWithCertAvailable extends MyModel {
private methodUsingBoxAvailableValue() {
// do something assuming box available is false.
}
private methodUsingCertAvailableValue() {
// do something assuming box available is true.
}
}
// isBoxAvailable = true, isCertAvailable = true
export class MyModelWithBoxAvailableAndCertAvailable extends MyModel {
private methodUsingBoxAvailableValue() {
// do something assuming box available is true.
}
private methodUsingCertAvailableValue() {
// do something assuming box available is true.
}
}
// 4 cases:
new MyModelWithoutBoxAvailableAndWithoutCertAvailable(); // === new MyModel(false, false);
new MyModelWithBoxAvailableAndWithoutCertAvailable(); // === new MyModel(true, false);
new MyModelWithoutBoxAvailableAndWithCertAvailable(); // === new MyModel(false, true);
new MyModelWithBoxAvailableAndCertAvailable(); // === new MyModel(true, true); See that the above classes are specific to each of their 4 specific use cases. They do exactly 1 thing. Of course, the above code is contrived and likely does not make the most sense in your particular case. However, the general idea is removing Hope that helps! |
See https://github.com/Glavin001/tslint-clean-code/blob/master/src/tests/NoFlagArgsRuleTests.ts for currently passing tests. Feel free to submit a Pull Request if you think there is a bug to be fixed. |
@Glavin001 Following class shows error:
The text was updated successfully, but these errors were encountered: