Détail du package

tsdocstandard

Raynos95MIT16.2.2

A standard for JavaScript + jsdoc + typescript

JavaScript Standard Style, bikeshed, check, checker

readme

TSDoc Standard

Standard but also use TypeScript on JS files with jsdoc.

This standard configuration understands that you want to use typescript on .js files using jsdoc / tsdoc syntax.

The eslint configuration knows all about jsdoc & typescript to give you improved type safety on .js files with jsdoc annotations.

Motivation

This tsdocstandard is here to help you convert a standard JavaScript project into a JavaScript + jsdoc + typescript project.

To use tsdocstandard you do need some dependencies, namely npm install -D typescript and a ./tsconfig.json file.

Here is an example tsconfig.json

Once you run tsdocstandard expect to get 100 warnings about missing jsdoc annotations. That's the point, it will help you convert your JavaScript to typed JavaScript with jsdoc comments.

Once you fix all the missing annotations expect almost 100% type-coverage ; ( You can measure it with the type-coverage library ).

Comparison with ts-standard

There's also a ts-standard linter. However, that is meant to lint *.ts typescript files. This project tsdocstandard is to lint *.js files used with tsc --checkJs

Why use JS+JSDoc over TS ?

I found JS+JSDoc a better fit for open source libraries published to npm. TS is probably fine for a closed source app or server.

  • Using JS makes the package.json 10x simpler ( https://github.com/Raynos/fake-kms/pull/1/files#diff-b9cfc7f2cdf78a7f4b91a753d10865a2 )
  • No build step during development
  • External contributors for my library can just write JS, largest pool of possible contributors ( same reason i dont author/publish coffeescript )
  • The published artifact to npm is the one I wrote and is not some "compiled JS" output. Aka no source maps.
  • In general there are far fewer files checked into git with JS+JSDoc for a library published to npm.

Usage

To use tsdocstandard you want to replace standard with tsdocstandard and also install typescript

npm install tsdocstandard typescript -D
tsc && tsdocstandard

Since tsdocstandard relies on typescript in jsdoc you want to make sure your codebase "type checks" with tsc before running the linter with tsdocstandard otherwise some lint rules will fail due to a typescript type checking error.

To use typescript you need a tsconfig.json; for example you can use

{
  "compilerOptions": {
    "types": ["node"],
    "lib": ["es2018"],
    "noEmit": true,
    "module": "commonjs",
    "allowJs": true,
    "checkJs": true,
    "noFallthroughCasesInSwitch": true,
    "noImplicitReturns": true,
    "noUnusedLocals": true,
    "noUnusedParameters": true,
    "strict": true,
    "baseUrl": "./",
    "paths": {
      "*" : ["./types/*"]
    }
  },
  "include": [
    "types/**/*.d.ts",
    "*.js",
    "test/**/*.js"
  ]
}

Migration

If you want to migrate a larger codebase one file at it's recommended you install both standard & tsdocstandard.

Then use the tsdocstandard & standard keys in package.json

{
  "tsdocstandard": {
    "ignore": [
      "old-code.js"
    ]
  },
  "standard": {
    "ignore": [
      "new-code.js"
    ]
  }
}

Basically run both linters and ignore the files that have and have not been migrated.

Install

npm install -D typescript # dependency
npm install -D tsdocstandard

Status (Unstable)

Currently tsdocstandard is used in multiple repositories. I've applied it to existing TS code as well as added to a vanilla JS code.

I need to use this ruleset on a larger set of javascript files before I will be happy with it.

Any and all feedback is useful in issues or PRs

Known issues

There are limitations with the following rules

How to ignore files

Add a tsdocstandard key like documented for standard https://standardjs.com/#how-do-i-ignore-files

How to use in text editor.

I have standard vscode installed. You can configure it on a per project basis whether to use standard; semistandard or standardx. However if you edit the JSON file you can enter an arbitrary string like tsdocstandard.

As long as you install tsdocstandard globally and edit the VS code extension configuration to use the tsdocstandard engine which requires editing JSON as the UI only has three items in the dropdown.

Rules

Importantly:

  • jsdoc
  • @eslint-typescript

There's lots of rules. Plus standard as well.

Usage

Literally just like standard

changelog

semistandard Change Log

All notable changes to this project will be documented in this file. This project adheres to Semantic Versioning.

14.2.0 - 2019-09-14

  • Update eslint to 6.4.0

14.1.0 2019-09-04

Check standard changelog that covers all the updates in detail: https://standardjs.com/changelog

14.0.1 2019-08-19

Check standard changelog that covers all the updates in detail: https://standardjs.com/changelog

14.0.0 2019-08-19

Updated to eslint 6 and standard 13.0.0.

Check standard changelog that covers all the updates in detail: https://standardjs.com/changelog

13.0.0 2018-11-06

Updated to eslint 5 and standard 12.0.0 and the latest standard-engine.

Check standard changelog that covers all the updates in detail: https://standardjs.com/changelog

12.0.0 2017-12-19

Updated to eslint 4 and standard 11.0.0 and the latest standard-engine.

With the eslint update, there are a few rules that are more strict now. Thankfully running semistandard --fix will fix just about all of them!

Check standard changelog that covers all the updates in detail: https://standardjs.com/changelog

11.0.0 2017-04-20

Updated to match the latest standard v10.0.2 rules and the newest standard-engine features.

Check standard changelog that covers all the updates: https://github.com/feross/standard/blob/master/CHANGELOG.md

In summary:

  • using deprecated Node.js APIs is now considered an error. It's finally time to update those dusty old APIs!

New features

  • Update ESLint from 3.15.x to 3.19.x.
  • Node.js API: Add standard.lintTextSync method

New rules

(Estimated % of affected standard users, based on test suite in parens)

  • Disallow using deprecated Node.js APIs (node/no-deprecated-api) #693 (13%)
    • Ensures that code always runs without warnings on the latest versions of Node.js
    • Ensures that safe Buffer methods (Buffer.from(), Buffer.alloc()) are used instead of Buffer()
  • Enforce callbacks always called with Node.js-style error first (standard/no-callback-literal) #623 (3%)
    • Functions named callback or cb must be invoked with null, undefined, or an Error as the first argument
    • Disallows using a string instead of an Error object
    • Disallows confusing callbacks that do not follow the standard Node.js pattern
  • Disallow any imports that come after non-import statements (import/first) #806 (1%)
  • Disallow unnecessary return await (no-return-await) #695 (0%)
  • Disallow comma-dangle in functions (comma-dangle) #787 (0%)
  • Disallow repeated exports of names or defaults (import/export) #806 (0%)
  • Disallow import of modules using absolute paths (import/no-absolute-path) #806 (0%)
  • Disallow Webpack loader syntax in imports (import/no-webpack-loader-syntax) #806 (0%)
  • Disallow comparing against -0 (no-compare-neg-zero) #812 (0%)

Changed rules

  • Relax rule: allow using ...rest to omit properties from an object (no-unused-vars) #800
    • This is a common and useful pattern in React/JSX apps!
  • Relax rule: allow Flow import type statements (import/no-duplicates) #599
    • These are no longer considered to be "duplicate imports"
  • Relax rule: Treat process.exit() the same as throw in code path analysis (node/process-exit-as-throw) #699
    • Makes certain other rules work better and give fewer false positives
  • Relax rule: allow Unnecessary Labels (no-extra-label)
    • Redundant, since "no-labels" is already enabled, which is more restrictive

(from standard 10.0.2):

  • Relax rule: Disallow import of modules using absolute paths (import/no-absolute-path) #861
    • This rule was responsible for up to 25% of the running time of standard, so we are disabling it until its performance improves.

10.0.0 2017-03-06

Updated to match the latest standard rules and the newest standard-engine features.

@feross did a great writeup on the standard changelog that covers all the updates: https://github.com/feross/standard/blob/master/CHANGELOG.md

In summary:

New features

  • Update ESLint from 3.10.x to 3.15.x
  • 3 additional rules are now fixable with standard --fix

New rules

(Estimated % of affected standard users, based on test suite in parens)

Changed rules

  • Relax rule: allow TypeScript Triple-Slash Directives (spaced-comment) #660
  • Relax rule: allow Flow Comments (spaced-comment) #661

9.0.0 2016-09-03

Updated to match the latest standard rules and the newest standard-engine features.

@feross did a great writeup on the standard changelog that covers all the updates: https://github.com/feross/standard/blob/master/CHANGELOG.md

In summary:

New features

  • Upgrade to ESLint v3 (http://eslint.org/docs/user-guide/migrating-to-3.0.0)
    • BREAKING: Drop support for node < 4 (this was a decision made by the ESLint team)
  • Expose ESLint's --fix command line flag standard-engine/#107
    • Lightweight, no additional dependencies, fixes dozens of rules automatically
    • Note: for semistandard, we left the existing --format flag in place, which uses semistandard-format, but I highly recommend using --fix instead!

New rules

(Estimated % of affected standard users, based on test suite in parens)

Changed rules

8.0.0 2016-05-12

Updated to match the latest standard rules and use the latest version of semistandard-format.

New Rules

6.1.1 2016-06-17

  • Bump standard-engine to 1.8.1, which fixes an NPE. (thanks again @wombleton)

6.1.0 2015-06-16

6.0.0 2015-06-03

BREAKING CHANGE: New Rules

  • no-extra-semi - This rule is aimed at eliminating extra unnecessary semicolons. While not technically an error, extra semicolons can be a source of confusion when reading code.

  • semi-spacing - Disallow a space before semicolons and force a space after them.

5.0.0 2015-05-29

  • Updated to standard rules 2.0.0 BREAKING CHANGE: new rule operator-linebreak set to "after"

4.3.0 2015-05-29

  • Updated to standard-engine 1.6.0
  • alternate parsers are now supported. See README.md for details!

4.2.2 2015-05-25

  • Since standard-engine now supports passing a formatter, we've switched back to using it for the CLI.

4.2.1 2015-05-25

  • Bumped all dependencies to their latest minor versions in package.json
  • This includes a fix in standard-engine which dramatically speeds up lint times!

4.2.0 2015-05-20

  • Switch to using eslint-config-semistandard, which extends eslint-config-standard. This means that non-breaking changes in standard should automatically get reflected now!

  • Thanks to new collaborator @ricardofbarros, semistandard now has a --format (-F) flag! It uses his semistandard-format module which is a fork of standard-format. Good Stuff!

4.1.4 2015-05-02

  • Merged from standard: relax rule no-alert

4.1.3 - 2015-04-23

  • Merged from standard rules: relax no-lone-blocks rule for ES6 reasons

4.1.2 - 2015-04-16

  • Fixed programmatic usage so it actually works.

4.1.1 - 2015-04-15

  • Update standard-engine version to fix crash on absolute filesystem path

4.1.0 - 2015-04-14

Merged latest from standard 3.6.0:

  • Rule turned off: no-script-url
  • All warning rules changed to error
  • Changed space-before-function-parentheses to space-before-function-paren
  • new react rules added
    • "react/jsx-boolean-value": 2
    • "react/jsx-quotes": [2, "single", "avoid-escape"]
    • "react/jsx-no-undef": 2
    • "react/jsx-sort-props": 0
    • "react/no-unknown-property": 2

Updates from standard-engine

  • Ignore linting for all files in .gitignore.
  • Removed /git/** exclusion as its redundant.
  • Output errors to stdout instead of stderr.