Skip to content

Commit

Permalink
chore: document new xo.path api and deprecate file uri use
Browse files Browse the repository at this point in the history
  • Loading branch information
spence-s committed Nov 8, 2021
1 parent 11563dc commit ab77e0e
Show file tree
Hide file tree
Showing 4 changed files with 25 additions and 8 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
### 3.7

- Changes "xo.path" setting from a file uri to a path or relative path.

### 3.6

- Adds a configuration for node runtime (closes #103)
Expand Down
4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -79,8 +79,8 @@
null
],
"default": null,
"pattern": "^(file://|[.]/).*(.js)$",
"description": "Location the extension loads xo from. An absolute file uri or a path relative to the workspace folder."
"pattern": "^(.{0,2}/).*(.js)$",
"description": "An absolute or relative path to resolve xo from. Relative paths resolve with respect to the workspace folder."
},
"xo.runtime": {
"scope": "window",
Expand Down
11 changes: 9 additions & 2 deletions readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -92,11 +92,14 @@ Since linting occurs on any file change, large files with complex configurations
}
```

If you want to resolve xo from a custom path - such as a global node_modules folder, supply an absolute file uri. Must start with file:// and end with .js and should have all of its dependencies available to work properly. Could use with Deno or to have the xo library lint itself.
If you want to resolve xo from a custom path - such as a global node_modules folder, supply an absolute or relative path (with respect to the workspace folder directory). Could use with Deno, yarn pnp, or to have the xo library lint itself. By default xo is resolved from the workspace folders node_modules directory.

```json
{
"xo.path": "file:///path/to/node_modules/xo/index.js"
"xo.path": "/path/to/node_modules/xo/index.js",
}
{
"xo.path": "./node_modules/xo/index.js"
}
```

Expand All @@ -110,6 +113,10 @@ By default, VSCode starts xo with its own bundled nodejs version. This may cause

## Recent Updates

- v3.7.0

- Configuration for a custom "xo.path" now accepts an absolute or relative path. File uris deprecated.

- v3.6.0

- Adds a configuration for custom nodejs runtime for running the xo server.
Expand Down
14 changes: 10 additions & 4 deletions server/server.js
Original file line number Diff line number Diff line change
Expand Up @@ -461,16 +461,22 @@ class Linter {

let xoUri;
let xoFilePath;
if (!isSANB(customPath)) {
const useCustomPath = isSANB(customPath);
if (!useCustomPath) {
xoFilePath = await Files.resolve('xo', undefined, folderPath);
xoUri = URI.file(xoFilePath).toString();
} else if (customPath.startsWith('file://')) {
} else if (useCustomPath && customPath.startsWith('file://')) {
xoUri = customPath;
} else if (customPath.startsWith('./')) {
this.connection.console.warn(
'Using a file uri for "xo.path" setting is deprecated and will be removed in the future, please provide an absolute or relative path to the file.'
);
} else if (useCustomPath && path.isAbsolute(customPath)) {
xoUri = URI.file(customPath).toString();
} else if (useCustomPath && !path.isAbsolute(customPath)) {
xoUri = URI.file(path.join(folderPath, customPath)).toString();
} else {
throw new Error(
`Unknown path format “${customPath}”: Needs to start with “file://” or “./”`
`Unknown path format “${customPath}”: Needs to start with “/”, “./”, or "../"`
);
}

Expand Down

0 comments on commit ab77e0e

Please sign in to comment.