Tslint: [FeatureRequest] Print absolute file path instead of relative

Created on 28 Nov 2016  路  12Comments  路  Source: palantir/tslint

Feature request

Hello, I'm using tslint with Webstorm and it would be nice to have tappable linter output. Currently tslint can print only relative file path, but Webstorm requires absolute path :(
Actual result:
screen shot 2016-11-28 at 15 22 19

Expected result:
screen shot 2016-11-28 at 15 18 27

Most helpful comment

For all the VSCode Users, you can replace the problemMatcher in your task with this one, it will distinguish between absolute (C:/, D:/,...) Windows Paths, and relative ones (src/app/...)

    "problemMatcher": [{
            "owner": "tslint",
            "severity": "warning",
            "fileLocation": "absolute",
            "pattern": {
                "regexp": "^(\\S[:][\\/]\\S.*)\\[(\\d+), (\\d+)\\]:\\s+(.*)$",
                "file": 1,
                "line": 2,
                "column": 3,
                "message": 4
            }
        },
        {
            "owner": "tslint",
            "severity": "warning",
            "fileLocation": ["relative", "${workspaceRoot}"],
            "pattern": {
                "regexp": "^(\\S[^:][^\\/]\\S.*)\\[(\\d+), (\\d+)\\]:\\s+(.*)$",
                "file": 1,
                "line": 2,
                "column": 3,
                "message": 4
            }
        }

Now i get warnings in the Problems Tab!

All 12 comments

You could probably write this pretty easily using a custom formatter

Haha I came here to investigate the opposite problem (I only see absolute paths which are cluttering up the console). Maybe we should just switch machines, eh?

With version @ 4.3.1 the output I see is even worse as its mixed relative and absolute!

Some paths are relative and some are absolute. Obfuscated examples below

C:/Users/tim/Documents/....ts[16, 19]: Array type using 'T[]' is forbidden for non-simple types. Use 'Array<T>' instead.
C:/Users/tim/Documents/.....ts[11, 14]: Use an interface instead of a type literal.
src/resources/....ts[14, 31]: Identifier 'lenk' is never reassigned; use 'const' instead of 'let'.
src/resources/....ts[79, 5]: Expected a 'for-of' loop instead of a 'for' loop with this simple iteration
src/resources/...ts[86, 5]: Expected a 'for-of' loop instead of a 'for' loop with this 

If it's useful to add, I _also_ have mixed relative and absolute paths (on v4.0.2). At first I thought it was because of my set up (faking the application folder as an additional app node module so I can do package-relative imports) but it occurs regardless of whether I'm using that approach or not.

That said it hasn't impacted me personally because we use unix tools to filter and sort the output anyway and enough of the path remains to still identify everything easily.

I'm using vscode and the console output pattern matcher has to define whether the paths are relative or absolute. This means that whichever way I configure it, some of the paths are not recognised.

It is interesting how do you invoke TSLint so you have mixed path? Do you have any symlinks there?

I'm using:

tslint --config ./src/tslint.json --project tsconfig.json --type-check --force

All plain old files with no symlinks

tslint.json

{
  "extends": "tslint:latest",
  "rules": {
    "quotemark": [
      true,
      "single",
      "avoid-escape"
    ],
    "ordered-imports": [
      false
    ],
    "max-line-length": [
      false
    ],
    "max-classes-per-file": [
      false
    ],
    "trailing-comma": [
      false
    ],
    "no-trailing-whitespace": false,
    "member-ordering": [
      false
    ],
    "object-literal-sort-keys": false,
    "no-empty": false,
    "object-literal-key-quotes": [
      false
    ],
    "no-unused-variable": true,
    "radix": false,
    "no-null-keyword": true,
    "no-angle-bracket-type-assertion": true,
    "triple-equals": [
      true,
      "allow-undefined-check"
    ],
    "arrow-parens": false,
    "array-type": [
      true,
      "array"
    ],
    "prefer-const": true,
    "prefer-for-of": false
  }
}

tsconfig.json

{
  "compileOnSave": false,
  "compilerOptions": {
    "allowJs": true,
    "rootDir": "./src/",
    "outDir": "./www/dist/",
    "inlineSources": true,
    "inlineSourceMap": true,
    "target": "es5",
    "module": "system",
    "declaration": false,
    "noImplicitAny": true,
    "strictNullChecks": false,
    "removeComments": false,
    "emitDecoratorMetadata": true,
    "experimentalDecorators": true,
    "moduleResolution": "node",
    "lib": [
      "es2015",
      "dom"
    ]
  },
  "include": [
    "./node_modules/@types/**/*.d.ts",
    "./www/jspm_packages/**/*.d.ts",
    "./typings/index.d.ts",
    "./typings/custom/**/*.d.ts",
    "./src/**/*.ts"
  ],
  "exclude": [
    "./src/**/*spec.ts",
    "node_modules",
    "platforms",
    "www"
  ]
}

No symlinks here. My command is:

tslint --type-check --config config/tslint.json --project tsconfig.json

I usually run this via npm scripts.

I don't think there's anything notable in my tslint config (just enabling rules and setting the custom directory). For tsconfig, I'm using commonjs modules with node resolution.

As previously mentioned, I use some module-style imports to access local files like so:

import { AlertService } from "app/common/alert.service";

But I've experimented with traditional relative imports and that seems to have no bearing on the mixed paths issue. I can try to double-check this again soon though.

Here are some slightly less obfuscated warnings, this time with msbuild formatter.

Points to note:

  • It seems unrelated to the rule which is failing.
  • It always switches from absolute to relative somewhere towards the end.
  • Its repeatable. If I run the command again, I get the same output
c:/Users/tim/Documents/Project/src/components/confirm-dialog.ts(25,1): warning maxClassesPerFile: A maximum of 1 class per file is allowed
c:/Users/tim/Documents/Project/src/components/confirm-dialog.ts(31,1): warning maxClassesPerFile: A maximum of 1 class per file is allowed
c:/Users/tim/Documents/Project/src/components/confirm-dialog.ts(37,1): warning maxClassesPerFile: A maximum of 1 class per file is allowed
c:/Users/tim/Documents/Project/src/components/confirm-dialog.ts(43,1): warning maxClassesPerFile: A maximum of 1 class per file is allowed
c:/Users/tim/Documents/Project/src/devices/controls/edit-channel/dialog.ts(156,1): warning maxClassesPerFile: A maximum of 1 class per file is allowed
c:/Users/tim/Documents/Project/src/devices/controls/edit-channel/dialog.ts(162,1): warning maxClassesPerFile: A maximum of 1 class per file is allowed
c:/Users/tim/Documents/Project/src/devices/controls/edit-channel/dialog.ts(168,1): warning maxClassesPerFile: A maximum of 1 class per file is allowed
c:/Users/tim/Documents/Project/src/devices/controls/edit-channel/dialog.ts(174,1): warning maxClassesPerFile: A maximum of 1 class per file is allowed
c:/Users/tim/Documents/Project/src/utils/color/color-convert.ts(31,1): warning maxClassesPerFile: A maximum of 1 class per file is allowed
c:/Users/tim/Documents/Project/src/devices/dal/device-configure.ts(66,13): warning typeofCompare: typeof must be compared to correct value
src/graph/components/axis/x-axis.ts(42,1): warning maxClassesPerFile: A maximum of 1 class per file is allowed
src/graph/components/axis/y-axis.ts(34,1): warning maxClassesPerFile: A maximum of 1 class per file is allowed

I've also started experiencing mixed relative and absolute paths in the output, but I think I know what caused it (roughly). All my paths were relative until I added some rules which required type checking, then I switched to using --project path/to/tsconfig.json and --type-check. Prior to that, I was just using a file glob: path/to/**/*.ts.

This is using Windows 7. I just confirmed that removing those rules and going back to the glob instead of the project that they all return to relative.

Mine switch back and forth between absolute and relative a couple times. The rules don't seem to matter, but the paths for a single file tend to always be the same style.

For all the VSCode Users, you can replace the problemMatcher in your task with this one, it will distinguish between absolute (C:/, D:/,...) Windows Paths, and relative ones (src/app/...)

    "problemMatcher": [{
            "owner": "tslint",
            "severity": "warning",
            "fileLocation": "absolute",
            "pattern": {
                "regexp": "^(\\S[:][\\/]\\S.*)\\[(\\d+), (\\d+)\\]:\\s+(.*)$",
                "file": 1,
                "line": 2,
                "column": 3,
                "message": 4
            }
        },
        {
            "owner": "tslint",
            "severity": "warning",
            "fileLocation": ["relative", "${workspaceRoot}"],
            "pattern": {
                "regexp": "^(\\S[^:][^\\/]\\S.*)\\[(\\d+), (\\d+)\\]:\\s+(.*)$",
                "file": 1,
                "line": 2,
                "column": 3,
                "message": 4
            }
        }

Now i get warnings in the Problems Tab!

For osx/linux users:

"problemMatcher": [
                {
                    "base": "$tslint5",
                    "fileLocation": "absolute",
                    "pattern": {
                        "regexp": "^(WARNING|ERROR):(\\s+\\(/\\S*\\))?\\s+(/\\S.*)\\[(\\d+), (\\d+)\\]:\\s+(.*)$",
                        "severity": 1,
                        "file": 3,
                        "line": 4,
                        "column": 5,
                        "message": 6
                    }
                },
                {
                    "base": "$tslint5",
                    "fileLocation": "relative",
                    "pattern": {
                        "regexp": "^(WARNING|ERROR):(\\s+\\(/\\S*\\))?\\s+([^/]\\S.*)\\[(\\d+), (\\d+)\\]:\\s+(.*)$",
                        "severity": 1,
                        "file": 3,
                        "line": 4,
                        "column": 5,
                        "message": 6
                    }
                }
            ]
Was this page helpful?
0 / 5 - 0 ratings

Related issues

jacob-robertson picture jacob-robertson  路  3Comments

Ne-Ne picture Ne-Ne  路  3Comments

ghost picture ghost  路  3Comments

DanielKucal picture DanielKucal  路  3Comments

CSchulz picture CSchulz  路  3Comments