This repository has been archived by the owner on Dec 25, 2023. It is now read-only.
-
-
Notifications
You must be signed in to change notification settings - Fork 8
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add support for custom rules dirs (#75)
* Add support for custom rules dirs Resolves #68 * Changelog * Add a bunch of test files for custom rules * Work around directory mangling issue * add link to eslint config docs * Improve console output when linting fails * changelog * format
- Loading branch information
Showing
14 changed files
with
155 additions
and
13 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
// returns custom eslint rules directories | ||
export function getRulesDirs(): Array<string> | null { | ||
const rulesDirs: Array<string> = | ||
nova.config.get("apexskier.eslint.config.eslintRulesDirs", "array") ?? []; | ||
const workspaceRulesDirs = nova.workspace.config.get( | ||
"apexskier.eslint.config.eslintRulesDirs", | ||
"array" | ||
); | ||
if (workspaceRulesDirs) { | ||
for (const dir of workspaceRulesDirs) { | ||
if (!dir.trim()) { | ||
continue; | ||
} | ||
if (nova.path.isAbsolute(dir)) { | ||
rulesDirs.push(dir); | ||
} else if (nova.workspace.path) { | ||
rulesDirs.push(nova.path.join(nova.workspace.path, dir)); | ||
} else { | ||
nova.workspace.showErrorMessage( | ||
"Save your workspace before using a relative ESLint rules directories." | ||
); | ||
return null; | ||
} | ||
} | ||
} | ||
|
||
return ( | ||
rulesDirs | ||
.filter((d) => d.trim()) | ||
// hack - JSON stringifying works around https://github.com/eslint/eslint/issues/14025 by forcing levn to parse as a string, not a regex | ||
// I could try to strip the `/Volumes/Macintosh HD` from Nova's workspace dir, but that would have to be | ||
// conditional, since global settings won't include it. This feels simpler, although it could break if eslint's options parsing changes | ||
.map((d) => JSON.stringify(d)) | ||
); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
module.exports = { | ||
plugins: ["custom-rules"], | ||
extends: ["../../.eslintrc"], | ||
rules: { | ||
"custom-rules/test-rule": 1, | ||
}, | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
`index.js` should have one warning (custom-rules/test-rule) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
module.exports = { | ||
rules: { | ||
"test-rule": { | ||
create: function (context) { | ||
return { | ||
TemplateLiteral(node) { | ||
context.report(node, "template literals show test-rule error"); | ||
}, | ||
}; | ||
}, | ||
}, | ||
}, | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
{ | ||
"name": "eslint-plugin-custom-rules", | ||
"version": "0.0.0", | ||
"private": "true", | ||
"main": "index.js" | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
export function test(foo) { | ||
console.log(`hello ${foo}`); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
module.exports = { | ||
plugins: ["custom-rules"], | ||
extends: ["../../.eslintrc"], | ||
rules: { | ||
"custom-rules/test-rule": 1, | ||
}, | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
`index.js` should have one warning (custom-rules/test-rule) when the project has custom rules configured: | ||
|
||
``` | ||
"apexskier.eslint.config.eslintRulesDirs" : [ | ||
"test\/rules-1\/custom-rules" | ||
], | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
export function test(foo) { | ||
console.log(`hello ${foo}`); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters