Skip to content
This repository has been archived by the owner on Mar 25, 2021. It is now read-only.

[FeatureRequest] Print absolute file path instead of relative #1794

Closed
SergeyKorochansky opened this issue Nov 28, 2016 · 12 comments · Fixed by #2667
Closed

[FeatureRequest] Print absolute file path instead of relative #1794

SergeyKorochansky opened this issue Nov 28, 2016 · 12 comments · Fixed by #2667

Comments

@SergeyKorochansky
Copy link

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

@nchen63
Copy link
Contributor

nchen63 commented Nov 28, 2016

You could probably write this pretty easily using a custom formatter

@tdsmithATabc
Copy link
Contributor

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?

@timfish
Copy link

timfish commented Jan 11, 2017

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 

@tdsmithATabc
Copy link
Contributor

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.

@timfish
Copy link

timfish commented Jan 11, 2017

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.

@IllusionMH
Copy link
Contributor

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

@timfish
Copy link

timfish commented Jan 11, 2017

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"
  ]
}

@tdsmithATabc
Copy link
Contributor

tdsmithATabc commented Jan 11, 2017

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.

@timfish
Copy link

timfish commented Jan 11, 2017

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

@colinbate
Copy link

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.

NikitaEgorov pushed a commit to NikitaEgorov/SonarTsPlugin that referenced this issue Jan 30, 2017
@Nefarion
Copy link

Nefarion commented Feb 17, 2017

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!

@rweng
Copy link

rweng commented Apr 22, 2017

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
                    }
                }
            ]

nchen63 added a commit that referenced this issue May 2, 2017
nchen63 added a commit that referenced this issue May 4, 2017
nchen63 added a commit that referenced this issue May 4, 2017
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

8 participants