Socket
Book a DemoInstallSign in
Socket

smart-tslint-rules

Package Overview
Dependencies
Maintainers
1
Versions
2
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

smart-tslint-rules

Human-friendly tslint rules

0.0.2
latest
Source
npmnpm
Version published
Maintainers
1
Created
Source

smart-tslint-rules

Human-friendly tslint rules

What is it?

smart-tslint-rules is set of TSLint rules to:

  • control string literal quotes to use ' ` or " with ability to fine-tune or disable for special cases;
  • disable or limit usage of "+" for string literar concatenation - prefer template string ;

Install

Install the package using NPM:

npm install smart-tslint-rules --save-dev

Usage

smart-tslint-rules has peer dependencies on TSLint and TypeScript.

To use these lint rules with the default preset, use configuration inheritance via the extends keyword. Here's a sample configuration where tslint.json lives adjacent to your node_modules folder:

{
  "extends": ["tslint:latest", "smart-tslint-rules"],
  "rules": {
    "quotemark-smart": true,
    "restrict-literal-concat": true
  }
}

To lint your .ts and .tsx files you can simply run tslint -c tslint.json 'src/**/*.{ts,tsx}'.

Rules

quotemark-smart (with Fix)

Requires single or double quotes for string literals based on literal content.

Configuration object may be optionally provided (defaults listed):

{
  default: "'",
  // allow both single or double but not \`tagged\`
  jsx: "'\"",
  empty: "'\"",
  singleChar: "'",
  startsWithDot: "\"",
  startsWithDigit: "\"",
  multiWord: "\"",
  longLiteral: "\"",
  longLimit: 30,
  shortLiteral: "'",
  shortLimit: 10,
  avoidEscape: true,
  avoidTemplate: true,
}

For example, `[true, "singleChar": ""'" ]` would not report a failure on the string literals "a" or 'a'.`,

Individual rules can be enabled and configured to express preference and smooth the transitions. E.g. start with allowing both kinds of quotes for all but long words and then gradually restrict the ruleset.

restrict-literal-concat

Prefer template literals to string concatenation.

Short literal can be allowed with setting [true, { "allow-length": 5 }]

Setting allow-length to relatively high limit enables baby steps for removing '+' concatenation in a codebase.

Help needed

  • Documentation
  • Ideas for improvements
  • New 'smart' rules - especially ones that can be realistically applied in existing codebases
  • Tests

Keywords

tslint

FAQs

Package last updated on 12 Oct 2018

Did you know?

Socket

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.

Install

Related posts

SocketSocket SOC 2 Logo

Product

About

Packages

Stay in touch

Get open source security insights delivered straight into your inbox.

  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc

U.S. Patent No. 12,346,443 & 12,314,394. Other pending.