Skip to content

Commit

Permalink
Merge pull request #112 from pascalre/110-add-configuration-for-deeps…
Browse files Browse the repository at this point in the history
…ourceio

110 add configuration for deepsourceio
  • Loading branch information
pascalre committed Jan 4, 2023
2 parents 89a7c4d + f8ccca0 commit 1fe13c3
Show file tree
Hide file tree
Showing 23 changed files with 512 additions and 495 deletions.
4 changes: 4 additions & 0 deletions .deepsource.toml
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,8 @@ version = 1

[[analyzers]]
name = "javascript"
enabled = true

[[analyzers]]
name = "test-coverage"
enabled = true
26 changes: 13 additions & 13 deletions .dependency-cruiser.js
Original file line number Diff line number Diff line change
Expand Up @@ -45,19 +45,19 @@ module.exports = {
'core'
],
path: [
'^(v8\/tools\/codemap)$',
'^(v8\/tools\/consarray)$',
'^(v8\/tools\/csvparser)$',
'^(v8\/tools\/logreader)$',
'^(v8\/tools\/profile_view)$',
'^(v8\/tools\/profile)$',
'^(v8\/tools\/SourceMap)$',
'^(v8\/tools\/splaytree)$',
'^(v8\/tools\/tickprocessor-driver)$',
'^(v8\/tools\/tickprocessor)$',
'^(node-inspect\/lib\/_inspect)$',
'^(node-inspect\/lib\/internal\/inspect_client)$',
'^(node-inspect\/lib\/internal\/inspect_repl)$',
'^(v8/tools/codemap)$',
'^(v8/tools/consarray)$',
'^(v8/tools/csvparser)$',
'^(v8/tools/logreader)$',
'^(v8/tools/profile_view)$',
'^(v8/tools/profile)$',
'^(v8/tools/SourceMap)$',
'^(v8/tools/splaytree)$',
'^(v8/tools/tickprocessor-driver)$',
'^(v8/tools/tickprocessor)$',
'^(node-inspect/lib/_inspect)$',
'^(node-inspect/lib/internal/inspect_client)$',
'^(node-inspect/lib/internal/inspect_repl)$',
'^(async_hooks)$',
'^(punycode)$',
'^(domain)$',
Expand Down
21 changes: 18 additions & 3 deletions .github/workflows/action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,25 +10,40 @@ jobs:
build:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- name: Use Node.js
- name: Checkout code
uses: actions/checkout@v3

- name: Setup Node.js
uses: actions/setup-node@v3
with:
node-version: 16

- name: install
run: |
npm install
npm install -g yarn
npm install -g vsce
- name: lint
run: npm run lint

- name: static code analysis
run: npm run code-analysis

- name: test
uses: GabrielBB/xvfb-action@v1
with:
run: npm run coverage
- name: coverage

- name: Report test coverage to Coveralls
uses: coverallsapp/github-action@master
with:
github-token: ${{ secrets.GITHUB_TOKEN }}

- name: Report test coverage to DeepSource
uses: deepsourcelabs/test-coverage-action@master
with:
key: javascript
coverage-file: coverage/lcov.info
dsn: ${{ secrets.DEEPSOURCE_DSN }}

10 changes: 9 additions & 1 deletion CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,9 @@ The following commands support you at developing good code:
* `npm run test`: Run the tests
* `npm run lint`: Run the linter

### SonarQube
### Static code analysis
#### SonarQube
##### Local
* `docker-compose up -d`: Start the sonarqube container. This will take some time.
* `docker-compose stop`: Stop the container
* `docker-compose down`: Remove the container
Expand All @@ -22,6 +24,12 @@ SonarQube will be reachable on `http://localhost:9000`.

* `npm run sonar`: Start sonarscanner and upload result to local container

##### SonarCloud
Find analysis on [sonarcloud.io](https://sonarcloud.io/project/overview?id=pascalre_vscode-yaml-sort)

#### DeepSource
Find analysis on [deepsource.io](https://deepsource.io/gh/pascalre/vscode-yaml-sort)

### Commit changes
Refer to [this blogpost](https://cbea.ms/git-commit/#end) by cbeams when committing changes. Issue numbers can be added in braces to the end of the commit message.

Expand Down
28 changes: 14 additions & 14 deletions src/adapter/js-yaml-adapter.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { Settings } from "../settings"
import * as jsyaml from "js-yaml"
import { load, dump } from "js-yaml"
import { SortUtil } from "../util/sort-util"
import { removeTrailingCharacters, splitYaml } from "../util/yaml-util"

Expand All @@ -15,7 +15,7 @@ export class JsYamlAdapter {
}

load(text: string) {
return jsyaml.load(text, this.getLoadOptions())
return load(text, this.getLoadOptions())
}

/**
Expand All @@ -25,7 +25,7 @@ export class JsYamlAdapter {
*/
validateYaml(text: string): boolean {
splitYaml(text).forEach((yaml) => {
jsyaml.load(yaml, { schema: this.settings.getSchema() })
load(yaml, { schema: this.settings.getSchema() })
})
return true
}
Expand All @@ -37,23 +37,23 @@ export class JsYamlAdapter {
* @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 {
dumpYaml(text: string, sortKeys: boolean, custom: number): string {

if (Object.keys(text).length === 0) {
return ""
}

const sort = new SortUtil(settings, custom)
const sort = new SortUtil(this.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) => {
let yaml = dump(text, {
indent: this.settings.getIndent(),
forceQuotes: this.settings.getForceQuotes(),
lineWidth: this.settings.getLineWidth(),
noArrayIndent: this.settings.getNoArrayIndent(),
noCompatMode: this.settings.getNoCompatMode(),
quotingType: this.settings.getQuotingType(),
schema: this.settings.getSchema(),
sortKeys: (!(custom > 0 && this.settings.getUseCustomSortRecursively()) ? sortKeys : (a: string, b: string) => {
return sort.customSort(a, b)
})
})
Expand Down
102 changes: 50 additions & 52 deletions src/adapter/vs-code-adapter.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import * as vscode from "vscode"
import { workspace, TextEditor, Range, Position, Selection, TextEdit, WorkspaceEdit, window, DocumentFormattingEditProvider, languages, Disposable } from "vscode"
import { Settings } from "../settings"

export enum Severity {
Expand All @@ -14,85 +14,83 @@ export class VsCodeAdapter {
}

getProperty(property: string) {
return vscode.workspace.getConfiguration().get(`${this.section}.${property}`)
return workspace.getConfiguration().get(`${this.section}.${property}`)
}

getActiveDocument(textEditor: vscode.TextEditor) {
return textEditor.document.getText()
// have a function that adds/removes the formatter based
// on a configuration setting
registerFormatter(formatter: DocumentFormattingEditProvider) {
let registration: Disposable | undefined
const useAsFormatter = this.settings.getUseAsFormatter()
if (useAsFormatter && !registration) {
languages.registerDocumentFormattingEditProvider('yaml', formatter)
} else if (!useAsFormatter && registration) {
registration.dispose()
}
}

showMessage(severity: Severity, message: string) {
if (severity === Severity.ERROR) {
window.showErrorMessage(message)
} else {
if (this.settings.getNotifySuccess()) {
window.showInformationMessage(message)
}
}
}

static getText(textEditor: TextEditor, range: Range) {
return textEditor.document.getText(range)
}

getFullDocumentRange(textEditor: vscode.TextEditor) {
return new vscode.Range(
new vscode.Position(0, 0),
new vscode.Position(textEditor.document.lineCount + 1, 0))
static getFullDocumentRange(textEditor: TextEditor) {
return new Range(
new Position(0, 0),
new Position(textEditor.document.lineCount + 1, 0))
}

getSelectedRange(textEditor: vscode.TextEditor) {
static getSelectedRange(textEditor: 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(
return new 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)
static applyEdits(edit: [TextEdit]) {
if (window.activeTextEditor) {
const workspaceEdit = new WorkspaceEdit()
workspaceEdit.set(window.activeTextEditor.document.uri, edit)
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()
}
static getActiveDocument(textEditor: TextEditor) {
return textEditor.document.getText()
}

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
static getRange(textEditor: TextEditor) {
if (textEditor.selection.isEmpty) {
return VsCodeAdapter.getFullDocumentRange(textEditor)
} else {
return VsCodeAdapter.getSelectedRange(textEditor)
}
}

static getEdits(textEditor: TextEditor, text: string) {
const range = VsCodeAdapter.getRange(textEditor)
return TextEdit.replace(range, text)
}

}

Loading

0 comments on commit 1fe13c3

Please sign in to comment.