Skip to content

Commit 99ea368

Browse files
committed
Adding tests
1 parent 047b6f4 commit 99ea368

File tree

12 files changed

+11585
-2087
lines changed

12 files changed

+11585
-2087
lines changed

.eslintrc.js

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
module.exports = {
2+
parser: '@babel/eslint-parser',
3+
plugins: ['node', 'jest', 'prettier'],
4+
extends: [
5+
'eslint:recommended',
6+
'plugin:node/recommended',
7+
'plugin:jest/recommended',
8+
'plugin:jest/style',
9+
'plugin:unicorn/recommended',
10+
'prettier',
11+
],
12+
parserOptions: {
13+
ecmaVersion: 2018,
14+
sourceType: 'script',
15+
requireConfigFile: false,
16+
},
17+
env: {
18+
browser: false,
19+
node: true,
20+
es6: true,
21+
},
22+
rules: {
23+
'unicorn/prefer-module': 'off',
24+
},
25+
overrides: [
26+
{
27+
files: ['__tests__/**/*.js'],
28+
env: {
29+
jest: true,
30+
},
31+
},
32+
],
33+
};

.github/dependabot.yml

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
version: 2
2+
updates:
3+
- package-ecosystem: npm
4+
directory: "/"
5+
schedule:
6+
interval: weekly
7+
time: "04:00"
8+
open-pull-requests-limit: 10

.github/workflows/auto-merge.yml

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
name: auto-merge
2+
3+
on:
4+
pull_request:
5+
6+
jobs:
7+
auto-merge:
8+
runs-on: ubuntu-latest
9+
steps:
10+
- uses: actions/checkout@v2
11+
- uses: ahmadnassri/action-dependabot-auto-merge@v2
12+
with:
13+
target: minor
14+
github-token: ${{ secrets.AUTO_MERGE }}

.github/workflows/ci-build.yml

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
name: CI Build
2+
3+
on:
4+
push:
5+
branches:
6+
- master
7+
- 'v*'
8+
pull_request: {}
9+
schedule:
10+
- cron: '0 3 * * *' # daily, at 3am
11+
12+
jobs:
13+
test:
14+
name: Tests
15+
runs-on: ${{matrix.os}}
16+
17+
strategy:
18+
matrix:
19+
os: [ubuntu-latest, windows-latest]
20+
node: ['12']
21+
22+
steps:
23+
- uses: actions/checkout@v1
24+
- uses: volta-cli/action@v1
25+
with:
26+
node-version: ${{ matrix.node }}
27+
- name: install dependencies
28+
run: yarn install
29+
- name: lint
30+
run: yarn lint
31+
- name: test
32+
run: yarn test:jest

.npmignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
__tests__

README.md

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
# @scalvert/ember-template-lint-formatter-sonarqube
2+
3+
![CI Build](https://github.com/scalvert/ember-template-lint-formatter-sonarqube/workflows/CI%20Build/badge.svg)
4+
[![npm version](https://badge.fury.io/js/%40lint-todo%2Fember-template-lint-formatter-todo.svg)](https://badge.fury.io/js/%40lint-todo%2Fember-template-lint-formatter-todo)
5+
[![License](https://img.shields.io/npm/l/@scalvert/ember-template-lint-formatter-sonarqube.svg)](https://github.com/@scalvert/ember-template-lint-formatter-sonarqube/blob/master/package.json)
6+
![Dependabot](https://badgen.net/badge/icon/dependabot?icon=dependabot&label)
7+
![Volta Managed](https://img.shields.io/static/v1?label=volta&message=managed&color=yellow&logo=data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAABAAAAAQCAYAAAAf8/9hAAAABmJLR0QAeQC6AMEpK7AhAAAACXBIWXMAAAsSAAALEgHS3X78AAAAB3RJTUUH5AMGFS07qAYEaAAAABl0RVh0Q29tbWVudABDcmVhdGVkIHdpdGggR0lNUFeBDhcAAAFmSURBVDjLY2CgB/g/j0H5/2wGW2xyTAQ1r2DQYOBgm8nwh+EY6TYvZtD7f9rn5e81fAGka17GYPL/esObP+dyj5Cs+edqZsv/V8o//H+z7P+XHarW+NSyoAv8WsFszyKTtoVBM5Tn7/Xys+zf7v76vYrJlPEvAwPjH0YGxp//3jGl/L8LU8+IrPnPUkY3ZomoDQwOpZwMv14zMHy8yMDwh4mB4Q8jA8OTgwz/L299wMDyx4Mp9f9NDAP+bWVwY3jGsJpB3JaDQVCEgYHlLwPDfwYWRqVQJgZmHoZ/+3PPfWP+68Mb/Pw5sqUoLni9ipuRnekrAwMjA8Ofb6K8/PKBF5nU7RX+Hize8Y2DOZTP7+kXogPy1zrH+f/vT/j/Z5nUvGcr5VhJioUf88UC/59L+/97gUgDyVH4YzqXxL8dOs/+zuFLJivd/53HseLPPHZPsjT/nsHi93cqozHZue7rLDYhUvUAADjCgneouzo/AAAAAElFTkSuQmCC&link=https://volta.sh)
8+
[![Code Style: prettier](https://img.shields.io/badge/code_style-prettier-ff69b4.svg?style=flat-square)](#badge)
9+
10+
> A custom formatter for `ember-template-lint` that will format the output in SonarQube's [generic issue format](https://docs.sonarqube.org/latest/analysis/generic-issue/).
11+
12+
## Install
13+
14+
```shell
15+
npm i @scalvert/ember-template-lint-formatter-sonarqube --save-dev
16+
17+
# or
18+
19+
yarn add @scalvert/ember-template-lint-formatter-sonarqube --dev
20+
```
21+
22+
## Usage
23+
24+
```shell
25+
ember-template-lint . --format @scalvert/ember-template-lint-formatter-sonarqube
26+
```

__tests__/index-test.js

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
const stripAnsi = require("strip-ansi");
2+
const SonarQubeFormatter = require("../index");
3+
4+
class MockConsole {
5+
buffer = [];
6+
7+
get lines() {
8+
return this.buffer.map((message) => {
9+
return stripAnsi(message).trim();
10+
});
11+
}
12+
13+
log(message) {
14+
this.buffer.push(message);
15+
}
16+
17+
toString() {
18+
return stripAnsi(this.buffer.join("\n"));
19+
}
20+
}
21+
22+
describe("SonarQube Formatter", () => {
23+
it("can format output from no results", () => {
24+
let mockConsole = new MockConsole();
25+
let formatter = new SonarQubeFormatter({
26+
console: mockConsole,
27+
});
28+
29+
formatter.print([]);
30+
31+
expect(mockConsole.toString()).toMatchInlineSnapshot(`
32+
"{
33+
\\"issues\\": []
34+
}"
35+
`);
36+
});
37+
});

index.js

Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
const path = require('path');
2+
3+
const SONARQUBE_SEVERITY = {
4+
'-1': 'INFO', // todo
5+
1: 'MINOR', // warning
6+
2: 'CRITICAL', // error
7+
};
8+
9+
const SONARQUBE_TYPE = {
10+
'-1': 'CODE_SMELL', // todo
11+
1: 'CODE_SMELL', // warning
12+
2: 'BUG', // error
13+
};
14+
15+
module.exports = class SonarQubeFormatter {
16+
constructor(options = {}) {
17+
this.options = options;
18+
this.console = options.console || console;
19+
}
20+
21+
print(results) {
22+
const issues = [];
23+
for (const result of results) {
24+
let relativePath = path.relative(
25+
this.options.workingDir,
26+
result.filePath
27+
);
28+
29+
for (const message of result.messages) {
30+
issues.push({
31+
engineId: 'ember-template-lint',
32+
ruleId: message.rule,
33+
severity: SONARQUBE_SEVERITY[message.severity],
34+
type: SONARQUBE_TYPE[message.severity],
35+
primaryLocation: {
36+
message: message.message,
37+
filePath: relativePath,
38+
textRange: {
39+
startLine: message.line,
40+
startColumn: message.column,
41+
endLine: message.endLine,
42+
endColumn: message.endColumn,
43+
},
44+
},
45+
});
46+
}
47+
}
48+
49+
// eslint-disable-next-line unicorn/no-null
50+
this.console.log(JSON.stringify({ issues }, null, 2));
51+
}
52+
};

index.ts

Whitespace-only changes.

jest.config.js

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
module.exports = {
2+
snapshotFormat: {
3+
printBasicPrototype: false,
4+
},
5+
testEnvironment: 'node',
6+
testPathIgnorePatterns: ['/__fixtures__/'],
7+
};

0 commit comments

Comments
 (0)