Bug 1831354 Comment 0 Edit History

Note: The actual edited comment in the bug view page will always show the original commenter’s name and original timestamp.

I noticed  this when working with the prettier step of ESLint on comm-central code, but the issue is not limited to comm-central.

STR:
- Find a file a few paths deep that both ESLint and Prettier will check
- **cd to that file's directory**
- Modify the file, preferably in a way that both ESLint and Prettier will report an issue
- Run mach lint on the file **without changing your shell working directory**

EXPECTED:
- mach lint reports a single file with two errors, one from ESLint one from Prettier

ACTUAL:
- The output has two "files" with errors, the one from Prettier has an incorrect path.

See attachment.

**Why this matters for comm-central:**

comm-central has a `mach commlint` wrapper around  `mach lint` in order to pick up different config files and such.

For ESLint, to ensure that `comm/.eslintrc.js` related files are used, before running ESLint, the working directory is changed to `$topsrcdir/comm`. This works well, helps keep paths to files consistent, and is transparent to the developer running `mach lint`.

However, because of this bug, Prettier now reports all paths incorrectly. The "comm/" portion of the path is dropped resulting in paths like `/src/mozilla-central/mail/base/content/aboutDialog.js`.

The bug is actually [here](https://searchfox.org/mozilla-central/rev/5c922d8b93b43c18bf65539bfc72a30f84989003/python/mozlint/mozlint/result.py#122).

```python
if os.path.isabs(self.path):
    self.path = mozpath.normpath(self.path)
    self.relpath = mozpath.relpath(self.path, root)
else:
    self.relpath = mozpath.normpath(self.path)
    self.path = mozpath.join(root, self.path)
```

Context-wise, `self.path` is a path to a file with an "Issue", and this is post-init code for the Issue object that's supposed to make self.path absolute and self.relpath relative to $topsrcdir.

However, when the working directory is not $topsrcdir, the last `mozpath.join` line sets an invalid absolute path.

This potentially affects linters beyond ESLint and Prettier, though it's the first time I've encountered it.

There's two potential fixes I see: In run_prettier, make the paths output by Prettier absolute when building the Issue()  objects, or change the `mozpath.join` line to `mozpath.abspath`.

The later may cause odd  linter bugs elsewhere.
I noticed  this when working with the prettier step of ESLint on comm-central code, but the issue is not limited to comm-central.

STR:
- Find a file a few paths deep that both ESLint and Prettier will check
- **cd to that file's directory**
- Modify the file, preferably in a way that both ESLint and Prettier will report an issue
- Run mach lint on the file **without changing your shell working directory**

EXPECTED:
- mach lint reports a single file with two errors, one from ESLint one from Prettier

ACTUAL:
- The output has two "files" with errors, the one from Prettier has an incorrect path.

See attachment.

**Why this matters for comm-central:**

comm-central has a `mach commlint` wrapper around  `mach lint` in order to pick up different config files and such.

For ESLint, to ensure that `comm/.eslintignore` and `comm/.prettierignore` are used, before running ESLint, the working directory is changed to `$topsrcdir/comm`. This works well, helps keep paths to files consistent, and is transparent to the developer running `mach lint`.

However, because of this bug, Prettier now reports all paths incorrectly. The "comm/" portion of the path is dropped resulting in paths like `/src/mozilla-central/mail/base/content/aboutDialog.js`.

The bug is actually [here](https://searchfox.org/mozilla-central/rev/5c922d8b93b43c18bf65539bfc72a30f84989003/python/mozlint/mozlint/result.py#122).

```python
if os.path.isabs(self.path):
    self.path = mozpath.normpath(self.path)
    self.relpath = mozpath.relpath(self.path, root)
else:
    self.relpath = mozpath.normpath(self.path)
    self.path = mozpath.join(root, self.path)
```

Context-wise, `self.path` is a path to a file with an "Issue", and this is post-init code for the Issue object that's supposed to make self.path absolute and self.relpath relative to $topsrcdir.

However, when the working directory is not $topsrcdir, the last `mozpath.join` line sets an invalid absolute path.

This potentially affects linters beyond ESLint and Prettier, though it's the first time I've encountered it.

There's two potential fixes I see: In run_prettier, make the paths output by Prettier absolute when building the Issue()  objects, or change the `mozpath.join` line to `mozpath.abspath`.

The later may cause odd  linter bugs elsewhere.

Back to Bug 1831354 Comment 0