Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Canonical macOS root paths break linting with TypeScript parser #3

Closed
kopischke opened this issue Nov 24, 2020 · 5 comments
Closed
Assignees
Labels
bug Something isn't working
Milestone

Comments

@kopischke
Copy link
Owner

kopischke commented Nov 24, 2020

On Mac systems, /Volumes/<Drive name (defaults to “Macintosh HD”)> is the canonical root path returned by all file management Cocoa APIs, and hence by Nova’s APIs. That <Drive name> path is actually a symbolic link to the UNIX root path /, a situation which the TypeScript ESLint parser apparently is unable to handle (see #2 passim for notes on this).

Tentatively, there seem to be two solutions to this, both of which have stood up to (cursory) testing:

  • “UNIXalise” all paths, i.e. remove /Volumes/<Drive name> from all qualified paths.
  • Relativise all paths, i.e. make them relative to the config file directory.
@natesilva
Copy link

For the first solution, it will need special handling for external drives as they require the /Volumes/<Drive name> format. The correct path will be whatever is returned by the Node function path.resolve('.') when run from that directory.

I don’t see a way to detect whether a drive is external from the Nova Extensions API.

@kopischke
Copy link
Owner Author

Actually, I think I got that one solved:

Linting with typeScript

As it turns out, you don’t need to know if a drive is external because the quirk of the Nova path resolving function that got us into this mess can also be leveraged to get us out of it again. Specifically nova.path.normalize()will expand / to /Volumes/<Drive name>. This works for me:

function nixalize (path) {
  const normalised = nova.path.normalize(path)
  if (!nova.path.isAbsolute(normalised)) return normalised

  const parts = nova.path.split(normalised)
  if (parts.length <= 2) return normalised

  const root = nova.path.normalize('/')
  const same = nova.path.split(root).every((el, idx) => parts[idx] === el)
  return same
    ? nova.path.join(...['/'].concat(parts.slice(3)))
    : normalised
}

As a German, I find this quintessentially Münchhausenesque solution deeply satisfying.

Anyway, release coming up ASAP.

kopischke added a commit that referenced this issue Nov 24, 2020
Some parsers (like TypeScript’s) choke and die on Cocoa style qualified paths, i.e. those beginning with “/Volumes/Root Drive Name”. Converting such paths to a format more palatable to *nix sensibilities seems to solve the issue. Closes #3.
@kopischke kopischke added the bug Something isn't working label Nov 24, 2020
@kopischke kopischke self-assigned this Nov 24, 2020
@kopischke kopischke added this to the v1.3.0 milestone Nov 24, 2020
@kopischke
Copy link
Owner Author

I’ve pushed all the fixes to the dev branch. @natesilva would you like (and do you have the opportunity) to test it before I pull the trigger on the release?

@natesilva
Copy link

Testing now.

@natesilva
Copy link

It works!

kopischke added a commit that referenced this issue Nov 24, 2020
Some parsers (like TypeScript’s) choke and die on Cocoa style qualified paths, i.e. those beginning with “/Volumes/Root Drive Name”. Converting such paths to a format more palatable to *nix sensibilities seems to solve the issue. Closes #3.
kopischke added a commit that referenced this issue Nov 25, 2020
Some parsers (like TypeScript’s) choke and die on Cocoa style qualified paths, i.e. those beginning with “/Volumes/Root Drive Name”. Converting such paths to a format more palatable to *nix sensibilities seems to solve the issue. Closes #3.
kopischke added a commit that referenced this issue Nov 25, 2020
Some parsers (like TypeScript’s) choke and die on Cocoa style qualified paths, i.e. those beginning with “/Volumes/Root Drive Name”. Converting such paths to a format more palatable to *nix sensibilities seems to solve the issue. Closes #3.
kopischke added a commit that referenced this issue Nov 25, 2020
Some parsers (like TypeScript’s) choke and die on Cocoa style qualified paths, i.e. those beginning with “/Volumes/Root Drive Name”. Converting such paths to a format more palatable to *nix sensibilities seems to solve the issue. Closes #3.
kopischke added a commit that referenced this issue Nov 25, 2020
Some parsers (like TypeScript’s) choke and die on Cocoa style qualified paths, i.e. those beginning with “/Volumes/Root Drive Name”. Converting such paths to a format more palatable to *nix sensibilities seems to solve the issue. Closes #3.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants