Security News
Research
Data Theft Repackaged: A Case Study in Malicious Wrapper Packages on npm
The Socket Research Team breaks down a malicious wrapper package that uses obfuscation to harvest credentials and exfiltrate sensitive data.
tslint-consistent-codestyle
Advanced tools
Additional rules to enforce constistent code style with tslint
The tslint-consistent-codestyle package is a set of TSLint rules that aim to enforce a consistent coding style in TypeScript projects. It provides a variety of rules that help maintain code quality and readability by enforcing consistent naming conventions, import orders, and other stylistic choices.
Consistent Naming Conventions
This feature enforces consistent naming conventions for variables, functions, and other identifiers. The code sample shows a rule configuration that enforces camelCase naming for variables.
/* tslint.json */
{
"rules": {
"naming-convention": [true, {"type": "variable", "format": "camelCase"}]
}
}
Consistent Import Order
This feature ensures that import statements are ordered consistently. The code sample demonstrates a rule that enforces imports to be ordered with lowercase names first.
/* tslint.json */
{
"rules": {
"import-order": [true, {"order": "lowercase-first"}]
}
}
No Implicit Dependencies
This feature prevents the use of dependencies that are not explicitly listed in the project's package.json. The code sample shows a rule configuration that disallows implicit dependencies, even in development.
/* tslint.json */
{
"rules": {
"no-implicit-dependencies": [true, "dev"]
}
}
ESLint is a popular linting tool for JavaScript and TypeScript that provides a wide range of rules for enforcing code quality and style. Compared to tslint-consistent-codestyle, ESLint is more widely used and has a larger ecosystem of plugins and configurations, making it a versatile choice for projects that require extensive customization.
Prettier is an opinionated code formatter that enforces a consistent style by parsing code and re-printing it with its own rules. While it doesn't offer the same level of configurability as tslint-consistent-codestyle, it complements linting tools by ensuring consistent formatting across a codebase.
TSLint is a static analysis tool for TypeScript that provides a wide range of rules for code quality and style. TSLint itself is the base tool that tslint-consistent-codestyle extends with additional rules focused on consistent coding style.
The rules in this package can be used to enforce consistent code style.
Install from npm to your devDependencies (https://www.npmjs.com/package/tslint-consistent-codestyle)
npm install --save-dev tslint-consistent-codestyle
Configure tslint to use tslint-consistent-codestyle
:
This package provides an empty configuration preset that just contains the rulesDirectory
. That means you can easily use the rules in this package, but don't get any predefined configuration. To use it, just add it to the extends
array in your tslint.json
:
{
"extends": ["tslint-consistent-codestyle"]
"rules": {
...
}
}
As of tslint@5.2.0
you can also use tslint-consistent-codestyle
as rulesDirectory
:
{
"rulesDirectory": ["tslint-consistent-codestyle"]
"rules": {
...
}
}
Now configure some of the new rules.
This package provides all rules for both TSLint and Wotan.
To use rules from this package, add the following to your .wotanrc.yaml
file:
extends:
- tslint-consistent-codestyle # makes rules from the package available with the 'tcc/' prefix
rules: # now configure the rules you want to use, remember to use the 'tcc/' prefix
tcc/no-collapsible-if: error
tcc/no-unused:
options: 'ignore-parameters'
Rule | Description |
---|---|
const-parameters | Declare parameters as const with JsDoc /** @const */ |
early-exit | Recommends to use an early exit instead of a long if block. |
ext-curly | Enforces where to consistently use curly braces where not strictly necessary. |
naming-convention | Fine grained configuration to enforce consistent naming for almost everything. E.g. variables, functions, classes, methods, parameters, enums, etc. |
no-as-type-assertion | Prefer <Type>foo over foo as Type . |
no-accessor-recursion | Don't use get foo() { return this.foo; } . This is most likely a typo. |
no-collapsible-if | Identifies nested if statements that can be combined into one. |
no-else-after-return | Like no-else-return from eslint. |
no-return-undefined | Just return; instead of return undefined; . |
no-static-this | Ban the use of this in static methods. |
no-unnecessary-else | Like no-else-after-return but better. |
no-unnecessary-type-annotation | Finds type annotations that can safely be removed. |
no-unused | Find dead code and unused declarations. |
no-var-before-return | Checks if the returned variable is declared right before the return statement. |
object-shorthand-properties-first | Shorthand properties should precede regular properties. |
parameter-properties | Configure how and where to declare parameter properties. |
prefer-const-enum | Prefer const enum where possible. |
prefer-while | Prefer a while loop instead of a for loop without initializer and incrementer. |
FAQs
Additional rules to enforce constistent code style with tslint
We found that tslint-consistent-codestyle demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
Research
The Socket Research Team breaks down a malicious wrapper package that uses obfuscation to harvest credentials and exfiltrate sensitive data.
Research
Security News
Attackers used a malicious npm package typosquatting a popular ESLint plugin to steal sensitive data, execute commands, and exploit developer systems.
Security News
The Ultralytics' PyPI Package was compromised four times in one weekend through GitHub Actions cache poisoning and failure to rotate previously compromised API tokens.