Giter Site home page Giter Site logo

azz / prettier-tslint Goto Github PK

View Code? Open in Web Editor NEW
226.0 3.0 13.0 858 KB

Code ➡️ prettier ➡️ tslint --fix ➡️ Formatted Code ✨

Home Page: https://npm.im/prettier-tslint

License: MIT License

JavaScript 99.09% TypeScript 0.91%
prettier tslint typescript

prettier-tslint's People

Contributors

aleclarson avatar azz avatar dependabot[bot] avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar

prettier-tslint's Issues

high and moderate security vulns in 0.4.2 via globby and yargs dependencies

$  npm audit
# npm audit report

ansi-regex  >2.1.1 <5.0.1
Severity: moderate
 Inefficient Regular Expression Complexity in chalk/ansi-regex - https://github.com/advisories/GHSA-93q8-gq69-wqmw
fix available via `npm audit fix --force`
Will install [email protected], which is a breaking change
node_modules/ansi-regex
  strip-ansi  4.0.0 - 5.2.0
  Depends on vulnerable versions of ansi-regex
  node_modules/strip-ansi
    cliui  4.0.0 - 5.0.0
    Depends on vulnerable versions of strip-ansi
    node_modules/cliui
      yargs  8.0.0-candidate.0 - 15.0.0
      Depends on vulnerable versions of cliui
      Depends on vulnerable versions of yargs-parser
      node_modules/yargs
        prettier-tslint  >=0.3.0
        Depends on vulnerable versions of globby
        Depends on vulnerable versions of yargs
        node_modules/prettier-tslint
    string-width  2.1.0 - 4.1.0
    Depends on vulnerable versions of strip-ansi
    node_modules/string-width

glob-parent  <5.1.2
Severity: high
Regular expression denial of service - https://github.com/advisories/GHSA-ww39-953v-wcq6
fix available via `npm audit fix --force`
Will install [email protected], which is a breaking change
node_modules/glob-parent
  fast-glob  <=2.2.7
  Depends on vulnerable versions of glob-parent
  node_modules/fast-glob
    globby  8.0.0 - 9.2.0
    Depends on vulnerable versions of fast-glob
    node_modules/globby
      prettier-tslint  >=0.3.0
      Depends on vulnerable versions of globby
      Depends on vulnerable versions of yargs
      node_modules/prettier-tslint

yargs-parser  6.0.0 - 13.1.1
Severity: moderate
Prototype Pollution in yargs-parser - https://github.com/advisories/GHSA-p9pc-299p-vxgp
fix available via `npm audit fix --force`
Will install [email protected], which is a breaking change
node_modules/yargs-parser
  yargs  8.0.0-candidate.0 - 15.0.0
  Depends on vulnerable versions of cliui
  Depends on vulnerable versions of yargs-parser
  node_modules/yargs
    prettier-tslint  >=0.3.0
    Depends on vulnerable versions of globby
    Depends on vulnerable versions of yargs
    node_modules/prettier-tslint

10 vulnerabilities (6 moderate, 4 high)

Support TypeScript 4.x

Versions:

  • prettier-tslint version: 0.4.2

Problem description:

TypeScript has recently released a new update which bumped the major. Unfortunately, TypeScript doesn't adhere to semver (see microsoft/TypeScript#14116). This means that this package needs to update the typescript peerDependency to allow using TypeScript 4.0+ with it.

Suggested solution:

Using 2.5.3 || >=3.0.0 (or simply >=2.5.3 if all versions past v2.5.3 are supported) as the peer dependency version for the typescript package should fix this issue. See https://docs.npmjs.com/files/package.json#dependencies

prettier-tslint mangles imports when reordering

Environment:

  • VS Code 1.27.2
  • Prettier VS Code extension
  • prettier-tslint
  • "module": "commonjs" in tsconfig.json
  • "ordered-imports": true in tslint.json

Steps taken:

Created testing.ts with the following in it:

import crypto from 'crypto'
import path from 'path'
import fs from 'fs'

Upon calling "Format Document" in VS Code, it gets mangled to:

import crypto from 'crypto'
import fs from "f'path'ort path from "p'fs'

Correct is:

import crypto from 'crypto'
import fs from 'fs'
import path from 'path'

The vscode-tslint extension with tslint.autoFixOnSave set to true doesn't have this bug and correctly reorders imports on save.

Allow to specify tslint.json

Hey!

In angular project there are three tslint.json files for the project (shared), the code (in src) and e2e (in e2e).

Would be nice to have a possibility to specify the tslint.json file.

Regards,
TheAifam5

Using with typescript-tslint-plugin

Not sure how possible this is. You need to use this plugin to apply auto-fixes for rules with requiresTypeInfo enabled. It would be great if prettier-tslint could trigger those auto-fixes somehow.

Side note: It might be easier to run Prettier as a TSLint rule instead. See here

Accept array of files

Currently, if you want to lint / prettify files, you need to do them one at a time. When processing multiple files, I suspect it would probably execute much quicker if the fix and check methods accepted an array of files, so prettier and tslint could process them in bulk.

Translate TSLint max-line-length into Prettier printWidth automatically

Prettier's printWidth defaults to 80, which (if left unchanged) makes TSLint's max-line-length look broken. The reality is that users should be using Prettier options to control the maximum line length.

To ease the pain, this package could probably translate TSLint's max-line-length into Prettier's printWidth automatically when printWidth is not explicitly defined.

We could also warn when both are defined, but have different values.

Related: #15

Imports are mangled when using "ordered-imports" with prettier-vscode

Bug Report

  • VS Code version: 1.30.1
  • Prettier - Code formatter version: 1.7.3
  • TSLint version: 5.11.0
  • TypeScript version: 3.2.2
  • Running TSLint via: VSCode

TypeScript code being linted

import {NgModule} from '@angular/core'
import {AppComponent} from './app.component'
import {CommonModuleCustom} from './modules/common.module'
import {ElectronService} from './providers/electron.service'
import {LayoutComponent} from './components/layout/layout.component'

with tslint.json configuration:

  ordered-imports:
    - true
    - grouped-imports: false
      import-sources-order: case-insensitive
      named-imports-order: case-insensitive
      module-source-path: full
  # From tslint-eslint-rules
  object-curly-spacing: 
    - true
    - always

Actual behavior

image

Expected behavior

image

Reproduce

You can reproduce from this repository: https://github.com/liuweiGL/prettier-tslint-bug-reproduce

PS

I think the apply-fixes.js has some problems,the tslint‘s applyTSLintAllFixes function will update Program, but you don't.

Refrence from palantir/tslint#2864

Usage of `.prettierrc` breaks the tslint rules like single quote

What happens if I use ".prettierrc" file

PROBLEM
Some of the rules configured by tslint.json are not working. One such example is below

/* tslint.json */
"rules": {
    "quotemark": [true, "single", "jsx-double"]
},

PARTIAL WORKAROUND
As a workaround, we are using the below in .prettierrc and hence we cannot utilize 😭 more option like "jsx-double" which is best suited for react configured in tslint

/* .prettierrc */
{
    "printWidth": 120,  // workaround as 'printWidth' in settings.json / 'max-line-length' in tslint.json not working
    "singleQuote": true  // partial workaround as usage of '.prettierrc' breaks tslint.json 
}

Why do I use ".prettierrc" file

Since I use prettier, tslint as vscode plugins, I prefer maintaining configuration in .vscode/settings.json

/* .vscode/settings.json */
{
  "editor.formatOnSave": true,
  "eslint.autoFixOnSave": true,
  "prettier.eslintIntegration": true,
  "prettier.printWidth": 120,            // not working
  "prettier.tslintIntegration": true,    // enabled
  "tslint.autoFixOnSave": true
}

All the rules working as per the configuration in tslint.json and .vscode/settings.json except

  • printWidth which is configured in .vscode/settings.json.
  • "max-line-length": [true, 120] which is configured in tslint.json

Hence as a workaround, we are using .prettierrc file as suggested in #15 (comment) but this breaks some of the tslint.json rules as explained

tslint

When tslint fixing , don't you need to read the tslint.json configuration in your project?

VSCode integration

Hello.

I wanted to used a simple thing to get prettier and tslint working together (this project so :D) with VsCode, on save.

Is there any steps I'm missing ?

Low security vulnerability from yargs > yargs-parser

I'm using a 0.4.2 version of the prettier-tslint library and have a warning about one of your dependencies. Here is a report from yarn audit command:

┌───────────────┬──────────────────────────────────────────────────────────────┐
│ low           │ Prototype Pollution                                          │
├───────────────┼──────────────────────────────────────────────────────────────┤
│ Package       │ yargs-parser                                                 │
├───────────────┼──────────────────────────────────────────────────────────────┤
│ Patched in    │ >=13.1.2 <14.0.0 || >=15.0.1 <16.0.0 || >=18.1.2             │
├───────────────┼──────────────────────────────────────────────────────────────┤
│ Dependency of │ prettier-tslint                                              │
├───────────────┼──────────────────────────────────────────────────────────────┤
│ Path          │ prettier-tslint > yargs > yargs-parser                       │
├───────────────┼──────────────────────────────────────────────────────────────┤
│ More info     │ https://www.npmjs.com/advisories/1500                        │
└───────────────┴──────────────────────────────────────────────────────────────┘

[prettier-vscode] max-line-length does not work

When setting tslintIntegration to true, prettier does not take into account its print-width rule anymore, neither it takes the max-line-length rule from tslint for formatting line length. When formatting files, it acts as if the print-width would be 80.

Here is my configuration:

VS config (extract):

    "prettier.tslintIntegration": true,

tslint.yaml (extract):

extends:
  - >-
    common/tslint

common/tslint.yaml (extract):

  max-line-length:
    options:
      limit: 120

Print Width is not respected

Prettier in VSCode settings is set to 80. Tslint Integration has been set. tslint.json has "max-line-length": [true, 80]

I tried creating a .prettierrc.json file with "printWidth": 80 but it also doesn't work.

Is this a bug or am I missing something?

[prettier-vscode] semicolon does not work

When setting tslintIntegration to true, prettier does not take into account its semi rule anymore, neither it takes the semicolon rule from tslint, at least in interface definition.

For example, in my interface definition:

export interface ApiDefinition extends RoutesType {
  lang: {
    url: { langCode: string }
    data: undefined
    header: undefined
    return: void
  }
  securityToken: {
    url: undefined
    data: undefined
    header: undefined
    return: string
  }
}

code formatting adds semicolons at almost each line:

export interface ApiDefinition extends RoutesType {
  lang: {
    url: { langCode: string };
    data: undefined;
    header: undefined;
    return: void;
  }
  securityToken: {
    url: undefined;
    data: undefined;
    header: undefined;
    return: string;
  }
}

Here is my configuration:

VS config (extract):

    "prettier.tslintIntegration": true,

tslint.yaml (extract):

extends:
  - >-
    common/tslint

common/tslint.yaml (extract):

  semicolon:
    options:
      - never

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.