generated from userscripters/template
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
added CLI test for the --lint option (closes #126)
- Loading branch information
Showing
7 changed files
with
108 additions
and
28 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
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,11 @@ | ||
/// <reference path="../../src/linters/eslint-plugin-userscripts.d.ts" /> | ||
export declare type LintOptions = { | ||
fix?: boolean; | ||
isHomepageAllowed?: boolean; | ||
spaces?: number; | ||
}; | ||
export declare type LintResult = { | ||
error: string; | ||
headers: string; | ||
}; | ||
export declare const lintHeaders: (metadataBlock: string, options?: LintOptions) => Promise<LintResult>; |
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,24 @@ | ||
import { ESLint } from "eslint"; | ||
import { configs } from "eslint-plugin-userscripts"; | ||
export const lintHeaders = async (metadataBlock, options = {}) => { | ||
const { fix = false, isHomepageAllowed = false, spaces = 4 } = options; | ||
const eslint = new ESLint({ | ||
baseConfig: { | ||
plugins: ["userscripts"], | ||
rules: { | ||
...configs.recommended.rules, | ||
"userscripts/align-attributes": ["error", spaces], | ||
"userscripts/use-homepage-and-url": isHomepageAllowed ? "error" : "off", | ||
}, | ||
}, | ||
useEslintrc: false, | ||
fix, | ||
}); | ||
const results = await eslint.lintText(metadataBlock); | ||
const [{ output }] = results; | ||
const formatter = await eslint.loadFormatter("stylish"); | ||
return { | ||
error: await formatter.format(results), | ||
headers: fix && output ? output : metadataBlock | ||
}; | ||
}; |
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