-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
28 changed files
with
1,718 additions
and
1,277 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
services: | ||
sonarqube: | ||
platform: linux/amd64 | ||
container_name: sonarqube | ||
image: sonarqube:latest | ||
ports: | ||
- "9000:9000" | ||
- "9092:9092" |
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
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 |
---|---|---|
@@ -1,6 +1,8 @@ | ||
{ | ||
"$schema": "https://docs.renovatebot.com/renovate-schema.json", | ||
"extends": [ | ||
"config:base" | ||
"config:base", | ||
"schedule:monthly", | ||
"group:recommended" | ||
] | ||
} |
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,20 @@ | ||
/* eslint-disable no-undef */ | ||
// eslint-disable-next-line @typescript-eslint/no-var-requires | ||
const scanner = require('sonarqube-scanner'); | ||
scanner( | ||
{ | ||
serverUrl: 'http://localhost:9000', | ||
options : { | ||
'sonar.projectName': 'YAML Sort', | ||
'sonar.projectKey': 'vscode-yaml-sort', | ||
'sonar.sources': 'src', | ||
'sonar.language': 'typescript', | ||
'sonar.test.inclusions': 'src/**/*.test.ts', | ||
'sonar.exclusions': 'node_modules', | ||
'sonar.binaries': 'out', | ||
'sonar.tests': 'src/test', | ||
'sonar.typescript.lcov.reportPaths': 'coverage/lcov.info', | ||
} | ||
}, | ||
() => process.exit() | ||
); |
This file was deleted.
Oops, something went wrong.
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,67 @@ | ||
import { Settings } from "../settings" | ||
import * as jsyaml from "js-yaml" | ||
import { SortUtil } from "../util/sort-util" | ||
import { removeTrailingCharacters, splitYaml } from "../util/yaml-util" | ||
|
||
export class JsYamlAdapter { | ||
settings: Settings | ||
|
||
constructor(settings = new Settings()) { | ||
this.settings = settings | ||
} | ||
|
||
getLoadOptions() { | ||
return { schema: this.settings.getSchema() } | ||
} | ||
|
||
load(text: string) { | ||
return jsyaml.load(text, this.getLoadOptions()) | ||
} | ||
|
||
/** | ||
* Validates a yaml document | ||
* @param text Yaml document | ||
* @returns true if yaml is valid | ||
*/ | ||
validateYaml(text: string): boolean { | ||
splitYaml(text).forEach((yaml) => { | ||
jsyaml.load(yaml, { schema: this.settings.getSchema() }) | ||
}) | ||
return true | ||
} | ||
|
||
|
||
/** | ||
* Dumps a yaml with the user specific settings. | ||
* @param {string} text Yaml document which should be dumped. | ||
* @param {boolean} sortKeys If set to true, the function will sort the keys in the document. Defaults to true. | ||
* @returns {string} Clean yaml document. | ||
*/ | ||
dumpYaml(text: string, sortKeys: boolean, custom: number, settings: Settings): string { | ||
|
||
if (Object.keys(text).length === 0) { | ||
return "" | ||
} | ||
|
||
const sort = new SortUtil(settings, custom) | ||
|
||
let yaml = jsyaml.dump(text, { | ||
indent: settings.getIndent(), | ||
forceQuotes: settings.getForceQuotes(), | ||
lineWidth: settings.getLineWidth(), | ||
noArrayIndent: settings.getNoArrayIndent(), | ||
noCompatMode: settings.getNoCompatMode(), | ||
quotingType: settings.getQuotingType(), | ||
schema: settings.getSchema(), | ||
sortKeys: (!(custom > 0 && settings.getUseCustomSortRecursively()) ? sortKeys : (a: string, b: string) => { | ||
return sort.customSort(a, b) | ||
}) | ||
}) | ||
|
||
// this is neccesary to avoid linebreaks in a selection sort | ||
yaml = removeTrailingCharacters(yaml, 1) | ||
|
||
return yaml | ||
} | ||
|
||
} |
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,98 @@ | ||
import * as vscode from "vscode" | ||
import { Settings } from "../settings" | ||
|
||
export enum Severity { | ||
INFO, ERROR | ||
} | ||
|
||
export class VsCodeAdapter { | ||
section = "vscode-yaml-sort" | ||
settings: Settings | ||
|
||
constructor(settings = new Settings()) { | ||
this.settings = settings | ||
} | ||
|
||
getProperty(property: string) { | ||
return vscode.workspace.getConfiguration().get(`${this.section}.${property}`) | ||
} | ||
|
||
getActiveDocument(textEditor: vscode.TextEditor) { | ||
return textEditor.document.getText() | ||
} | ||
|
||
getFullDocumentRange(textEditor: vscode.TextEditor) { | ||
return new vscode.Range( | ||
new vscode.Position(0, 0), | ||
new vscode.Position(textEditor.document.lineCount + 1, 0)) | ||
} | ||
|
||
getSelectedRange(textEditor: vscode.TextEditor) { | ||
let endLine = textEditor.selection.end.line | ||
// if selection ends on the first character on a new line ignore this line | ||
if (textEditor.selection.end.character === 0) { | ||
endLine-- | ||
} | ||
|
||
// ensure selection covers whole start and end line | ||
return new vscode.Selection( | ||
textEditor.selection.start.line, 0, | ||
endLine, textEditor.document.lineAt(endLine).range.end.character) | ||
} | ||
|
||
getRange(textEditor: vscode.TextEditor) { | ||
if (textEditor.selection.isEmpty) { | ||
return this.getFullDocumentRange(textEditor) | ||
} else { | ||
return this.getSelectedRange(textEditor) | ||
} | ||
} | ||
|
||
getText(textEditor: vscode.TextEditor, range: vscode.Range) { | ||
return textEditor.document.getText(range) | ||
} | ||
|
||
getEdits(textEditor: vscode.TextEditor, text: string) { | ||
const range = this.getRange(textEditor) | ||
return vscode.TextEdit.replace(range, text) | ||
} | ||
|
||
/** | ||
* Applys edits to a text editor | ||
* @param activeEditor Editor to apply the changes | ||
* @param edits Changes to apply | ||
*/ | ||
applyEdits(edit: [vscode.TextEdit]) { | ||
if (vscode.window.activeTextEditor) { | ||
const workspaceEdit = new vscode.WorkspaceEdit() | ||
workspaceEdit.set(vscode.window.activeTextEditor.document.uri, edit) | ||
vscode.workspace.applyEdit(workspaceEdit) | ||
} | ||
} | ||
|
||
// have a function that adds/removes the formatter based | ||
// on a configuration setting | ||
registerFormatter(formatter: vscode.DocumentFormattingEditProvider) { | ||
let registration: vscode.Disposable | undefined | ||
const useAsFormatter = this.settings.getUseAsFormatter() | ||
if (useAsFormatter && !registration) { | ||
vscode.languages.registerDocumentFormattingEditProvider('yaml', formatter) | ||
} else if (!useAsFormatter && registration) { | ||
registration.dispose() | ||
} | ||
} | ||
|
||
showMessage(severity: Severity, message: string) { | ||
switch(severity) { | ||
case Severity.ERROR : | ||
vscode.window.showErrorMessage(message) | ||
break | ||
case Severity.INFO : | ||
if (this.settings.getNotifySuccess()) { | ||
vscode.window.showInformationMessage(message) | ||
} | ||
break | ||
} | ||
} | ||
} | ||
|
Oops, something went wrong.