Duplicated code can lead to software that is hard to understand and difficult to change. The Don't Repeat Yourself (DRY) principle states:
Every piece of knowledge must have a single, unambiguous, authoritative representation within a system.
When you violate DRY, bugs and maintenance problems are sure to follow. Duplicated code has a tendency to both continue to replicate and also to diverge (leaving bugs as two similar implementations differ in subtle ways).
Tuning
This issue has a mass of 49.
We set useful threshold defaults for the languages we support but you may want to adjust these settings based on your project guidelines.
The threshold configuration represents the minimum mass a code block must have to be analyzed for duplication. The lower the threshold, the more fine-grained the comparison.
If the engine is too easily reporting duplication, try raising the threshold. If you suspect that the engine isn't catching enough duplication, try lowering the threshold. The best setting tends to differ from language to language.
"jsx-single" enforces single quotes for JSX attributes.
"jsx-double" enforces double quotes for JSX attributes.
"avoid-template" forbids single-line untagged template strings that do not contain string interpolations.
Note that backticks may still be used if "avoid-escape" is enabled and both single and double quotes are
present in the string (the latter option takes precedence).
"avoid-escape" allows you to use the "other" quotemark in cases where escaping would normally be required.
For example, [true, "double", "avoid-escape"] would not report a failure on the string literal
'Hello "World"'.
"jsx-single" enforces single quotes for JSX attributes.
"jsx-double" enforces double quotes for JSX attributes.
"avoid-template" forbids single-line untagged template strings that do not contain string interpolations.
Note that backticks may still be used if "avoid-escape" is enabled and both single and double quotes are
present in the string (the latter option takes precedence).
"avoid-escape" allows you to use the "other" quotemark in cases where escaping would normally be required.
For example, [true, "double", "avoid-escape"] would not report a failure on the string literal
'Hello "World"'.
A consistent ordering for class members can make classes easier to read, navigate, and edit.
A common opposite practice to member-ordering is to keep related groups of classes together.
Instead of creating classes with multiple separate groups, consider splitting class responsibilities
apart across multiple single-responsibility classes.
Notes
Has Fix
Config
One argument, which is an object, must be provided. It should contain an order property.
The order property should have a value of one of the following strings:
fields-first
instance-sandwich
statics-first
fields-first puts, in order of precedence:
* fields before constructors before methods
* static members before instance members
* public members before protected members before private members
instance-sandwich puts, in order of precedence:
* fields before constructors before methods
* static fields before instance fields, but static methods after instance methods
* public members before protected members before private members
statics-first puts, in order of precedence:
* static members before instance members
* public members before protected members before private members
* fields before methods
* instance fields before constructors before instance methods
* fields before constructors before methods
* public members before protected members before private members
Note that these presets, despite looking similar, can have subtly different behavior due to the order in which these
rules are specified. A fully expanded ordering can be found in the PRESETS constant in
https://github.com/palantir/tslint/blob/master/src/rules/memberOrderingRule.ts.
(You may need to check the version of the file corresponding to your version of tslint.)
Alternatively, the value for order may be an array consisting of the following strings:
public-static-field
protected-static-field
private-static-field
public-static-method
private-static-method
protected-static-method
public-instance-field
protected-instance-field
private-instance-field
public-constructor
protected-constructor
private-constructor
public-instance-method
protected-instance-method
private-instance-method
public-static-accessor
protected-static-accessor
private-static-accessor
public-instance-accessor
protected-instance-accessor
private-instance-accessor
You can also omit the access modifier to refer to "public-", "protected-", and "private-" all at once; for example, "static-field".
You can also make your own categories by using an object instead of a string:
{
"name": "static non-private",
"kinds": [
"public-static-field",
"protected-static-field",
"public-static-method",
"protected-static-method"
]
}
The 'alphabetize' option will enforce that members within the same category should be alphabetically sorted by name.
Computed property names are sorted before others but not sorted amongst each other.
Additionally getters will be sorted before setters (after alphabetization).
"jsx-single" enforces single quotes for JSX attributes.
"jsx-double" enforces double quotes for JSX attributes.
"avoid-template" forbids single-line untagged template strings that do not contain string interpolations.
Note that backticks may still be used if "avoid-escape" is enabled and both single and double quotes are
present in the string (the latter option takes precedence).
"avoid-escape" allows you to use the "other" quotemark in cases where escaping would normally be required.
For example, [true, "double", "avoid-escape"] would not report a failure on the string literal
'Hello "World"'.
"jsx-single" enforces single quotes for JSX attributes.
"jsx-double" enforces double quotes for JSX attributes.
"avoid-template" forbids single-line untagged template strings that do not contain string interpolations.
Note that backticks may still be used if "avoid-escape" is enabled and both single and double quotes are
present in the string (the latter option takes precedence).
"avoid-escape" allows you to use the "other" quotemark in cases where escaping would normally be required.
For example, [true, "double", "avoid-escape"] would not report a failure on the string literal
'Hello "World"'.