Skip to content

Commit

Permalink
feat: add treatErrorsAsWarnings setting (#108)
Browse files Browse the repository at this point in the history
  • Loading branch information
jamesorlakin authored Nov 29, 2020
1 parent 3340002 commit 0f92bb6
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 15 deletions.
21 changes: 11 additions & 10 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -33,16 +33,17 @@

We give you some options to customize vscode-standardjs in your VSCode [`settings.json`](https://code.visualstudio.com/docs/getstarted/settings).

| Option | Description | Default |
| ----------------------------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ | ------------------------------------------------------------------- |
| `standard.enable` | enable or disable JavaScript Standard Style | `true` |
| `standard.run` | run linter `onSave` or `onType` | `onType` |
| `standard.autoFixOnSave` | enable or disable auto fix on save. It is only available when VSCode's `files.autoSave` is either `off`, `onFocusChange` or `onWindowChange`. It will not work with `afterDelay`. | `false` |
| `standard.nodePath` | use this setting if an installed `standard` package can't be detected. | `null` |
| `standard.validate` | an array of language identifiers specify the files to be validated | `["javascript", "javascriptreact", "typescript", "typescriptreact]` |
| `standard.workingDirectories` | an array for working directories to be used. | `[]` |
| `standard.engine` | You can use `semistandard`, `standardx` or `ts-standard` instead of `standard`. **Just make sure you've installed the `semistandard`, the `standardx` or the `ts-standard` package, instead of `standard`.** | `standard` |
| `standard.usePackageJson` | if set to `true`, JavaScript Standard Style will use project's `package.json` settings, otherwise globally installed `standard` module is used | `false` |
| Option | Description | Default |
| -------------------------------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ | ------------------------------------------------------------------- |
| `standard.enable` | enable or disable JavaScript Standard Style | `true` |
| `standard.run` | run linter `onSave` or `onType` | `onType` |
| `standard.autoFixOnSave` | enable or disable auto fix on save. It is only available when VSCode's `files.autoSave` is either `off`, `onFocusChange` or `onWindowChange`. It will not work with `afterDelay`. | `false` |
| `standard.nodePath` | use this setting if an installed `standard` package can't be detected. | `null` |
| `standard.validate` | an array of language identifiers specify the files to be validated | `["javascript", "javascriptreact", "typescript", "typescriptreact]` |
| `standard.workingDirectories` | an array for working directories to be used. | `[]` |
| `standard.engine` | You can use `semistandard`, `standardx` or `ts-standard` instead of `standard`. **Just make sure you've installed the `semistandard`, the `standardx` or the `ts-standard` package, instead of `standard`.** | `standard` |
| `standard.usePackageJson` | if set to `true`, JavaScript Standard Style will use project's `package.json` settings, otherwise globally installed `standard` module is used | `false` |
| `standard.treatErrorsAsWarnings` | Any linting error reported by Standard will instead be displayed as a warning within VS Code. | `false` |

## Configuring Standard

Expand Down
4 changes: 3 additions & 1 deletion client/src/extension.ts
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,7 @@ interface TextDocumentSettings {
workspaceFolder: VWorkspaceFolder | undefined
workingDirectory: DirectoryItem.DirectoryItem | undefined
library: undefined
treatErrorsAsWarnings: boolean
}

interface NoStandardState {
Expand Down Expand Up @@ -499,7 +500,8 @@ export function realActivate (context: ExtensionContext): void {
nodePath: config.get('nodePath', undefined),
workingDirectory: undefined,
workspaceFolder: undefined,
library: undefined
library: undefined,
treatErrorsAsWarnings: config.get('treatErrorsAsWarnings', false)
}
const document: TextDocument = syncedDocuments.get(item.scopeUri)
if (document == null) {
Expand Down
5 changes: 5 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -162,6 +162,11 @@
"type": "boolean",
"default": false,
"description": "Activate JavaScript Standard Style based on project's package.json settings, use globally installed standard module if set to \"false\""
},
"standard.treatErrorsAsWarnings": {
"type": "boolean",
"default": false,
"description": "Any linting error reported by Standard will instead be displayed as a warning within VS Code."
}
}
},
Expand Down
9 changes: 5 additions & 4 deletions server/src/server.ts
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,7 @@ interface TextDocumentSettings {
workspaceFolder: { name: string, uri: URI } | undefined
workingDirectory: DirectoryItem.DirectoryItem | undefined
library: StandardModule | undefined
treatErrorsAsWarnings: boolean
}

interface StandardAutoFixEdit {
Expand Down Expand Up @@ -135,7 +136,7 @@ interface StandardModule {

function makeDiagnostic (
problem: StandardProblem,
source: LinterValues
settings: TextDocumentSettings
): Diagnostic {
const message =
problem.ruleId != null
Expand All @@ -149,8 +150,8 @@ function makeDiagnostic (
problem.endColumn != null ? Math.max(0, problem.endColumn - 1) : startChar
return {
message: message,
severity: convertSeverity(problem.severity),
source: source,
severity: settings.treatErrorsAsWarnings ? DiagnosticSeverity.Warning : convertSeverity(problem.severity),
source: settings.engine,
range: {
start: { line: startLine, character: startChar },
end: { line: endLine, character: endChar }
Expand Down Expand Up @@ -968,7 +969,7 @@ function validate (
) {
docReport.messages.forEach(problem => {
if (problem != null) {
const diagnostic = makeDiagnostic(problem, settings.engine)
const diagnostic = makeDiagnostic(problem, settings)
diagnostics.push(diagnostic)
if (settings.autoFix) {
recordCodeAction(document, diagnostic, problem)
Expand Down

0 comments on commit 0f92bb6

Please sign in to comment.