Coder Social home page Coder Social logo

sonar-web-frontend-reporters's Introduction

Sonar Web Front-End Reporters

Build Status NPM version

sreporter is a Command-Line Interface to generate linters reporters for the SonarQube plugin.

Usage

There is two way of using sonar-web-frontend-reporters:

  • The Command-Line Interface way
  • The NodeJS way

Installation

$ npm install sonar-web-frontend-reporters -g           // For CLI use
$ npm install sonar-web-frontend-reporters --save-dev   // For NodeJS use

Command-Line Interface

Launch the CLI by calling:

$ sreporter [options]

Options

The command line utility has several options. You can view the options by running eslint -h.

Usage: sreporter [options]

Options:

  -h, --help           output usage information
  -V, --version        output the version number
  -c, --config <path>  Use configuration from this file. Defaults to ./.sreporterrc
  --es5                launch CLI with ES5 backward compatibility

The Command-Line Interface uses a configuration file (default is .sreporterrc) to define the reporters configuration. The configuration file is mandatory in order to use the CLI.

Default options are as follows:

{
  "projectName": "Sonar Web Front-End Reporter",
  "csslint": {
    "src": "src/**/*.css",
    "report": "reports/sonar/csslint.json",
    "rulesFile": ".csslintrc"
  },
  "sasslint": {
    "src": "src/**/*.scss",
    "report": "reports/sonar/scsslint.json",
    "rulesFile": ".sass-lint.yml"
  },
  "sass-to-scsslint": {
    "src": "src/**/*.scss",
    "report": "reports/sonar/scsslint.json",
    "rulesFile": ".sass-lint.yml"
  },
  "htmlhint": {
    "src": "src/**/*.html",
    "report": "reports/sonar/htmlhint.json",
    "rulesFile": ".htmlhintrc"
  },
  "eslint": {
    "src": "src/**/*.js",
    "report": "reports/sonar/eslint.json",
    "rulesFile": ".eslintrc",
    "ignorePath": ".eslintignore"
  },
  "eslintangular": {
    "src": "src/**/*.js",
    "report": "eslint-angular.json",
    "rulesFile": ".eslintrc",
    "ignorePath": ".eslintignore"
  },
  "jshint": {
    "src": "src/**/*.js",
    "report": "reports/sonar/jshint.json",
    "rulesFile": ".jshintrc"
  },
  "tslint": {
    "src": "src/**/*.ts",
    "report": "reports/sonar/tslint.json",
    "rulesFile": ".tslintrc"
  }
}

Disabling a reporter

Disabling a reporter is as simple as removing it from the .sreporterrc file.

You can also set it's property to false:

{
  "projectName": "Sonar Web Front-End Reporter",
  "csslint": false
}

ES5 backward compatibility

To use the CLI with older NodeJS versions, you can use the --es5 option:

$ sreporter --es5

NodeJS

You can launch all reporters:

const SonarWebReporters = require('sonar-web-frontend-reporters').Reporters;

let sonarWebReporters = new SonarWebReporters('Sonar Web Front-End Reporters', {
  "csslint": {
    "src": "src/**/*.css",
    "report": "reports/sonar/csslint.json",
    "rulesFile": ".csslintrc"
  },
  "htmlhint": {
    "src": "src/**/*.html",
    "report": "reports/sonar/htmlhint.json",
    "rulesFile": ".htmlhintrc"
  },
  "eslint": {
    "src": "src/**/*.js",
    "report": "reports/sonar/eslint.json",
    "rulesFile": ".eslintrc"
  }
});

sonarWebReporters.launchReporters(() => {
  console.log('All reporters have been processed');
});

Or just one by one, e.g for CSSLint:

const CSSLintReporter = require('sonar-web-frontend-reporters').CSSLintReporter;

let cssLintReporter = new CSSLintReporter({
  src      : 'src/**/*.css',
  report   : 'reports/sonar/csslint.json',
  rulesFile: '.csslintrc'
}, 'Sonar Web Front-End Reporters');

cssLintReporter.launch(() => {
  console.log('CSSLint reporter has been generated under reports/sonar/csslint.json');
});

ES5 backward compatibility

To use it with older NodeJS versions, you can require the reporters this way:

var SonarWebReporters = require('sonar-web-frontend-reporters/build/reporters');
var CSSLintReporter = require('sonar-web-frontend-reporters/build/reporters/csslint.reporter');

Available reporters

  • CSSLint
  • SASSLint
  • SASSLint to SCSSLint (convert SASSLint rules to SCSSLint rules, because the SonarQube plugin doesn't support SASSLint rules)
  • HTMLHint
  • ESLint
  • ESLint for AngularJS
  • JSHint
  • TSLint

Migrating from 2.x to 3.x

2.x and 3.x versions aren't compatible one to another.

The main reasons for this 3.0 version were that:

  • We wanted to remove the Gulp abstraction and create a cleaner and more reusable/maintainable code in full ES6 ;
  • We needed to use it in a Webpack project and the integration wasn't that easy.

Warning:

3.x version is compatible with NodeJS version >= 6.5.0 with ES6 support and >= 4.4.5 with ES5 backward compatibility

You can still use the Gulp version by installing [email protected].

However, you can also use it with Gulp this way:

let CSSLintReporter = require('sonar-web-frontend-reporters').CSSLintReporter;

gulp.task('csslint:reporter', (done) => {
  let cssLintReporter = new CSSLintReporter({
    src      : 'src/**/*.css',
    report   : 'reports/sonar/csslint.json',
    rulesFile: '.csslintrc'
  }, 'Sonar Web Front-End Reporters');

  cssLintReporter.launch(() => done());
});

Contributing

License

ISC License

Copyright (c) 2016 Groupe SII

sonar-web-frontend-reporters's People

Contributors

aurelien-baudet avatar cedric-legallo avatar earthcitizen avatar liollury avatar numminorihsf avatar valentingot avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

sonar-web-frontend-reporters's Issues

Error with NodeJS 5: "process.argv.includes is not a function"

Support for NodeJS < 6 seems to be broken in the final version 3.0.0;

es5 = (process.argv.includes('--es5') > -1),
                    ^
TypeError: process.argv.includes is not a function
  at Object.<anonymous> (C:\a\1\s\node_modules\sonar-web-frontend-reporters\bin\sreporter:7:23)
  at Module._compile (module.js:413:34)
  at Object.Module._extensions..js (module.js:422:10)
  at Module.load (module.js:357:32)
  at Function.Module._load (module.js:314:12)
  at Function.Module.runMain (module.js:447:10)
  at startup (node.js:148:18)
  at node.js:405:3

Non-angular ESLint reporter

Is there any possibility to develop a non-angular ESLint reporter?

Doesn't seem too hard, I can try myself if there isn't spare time to develop it.

Thanks!

Coverage reports

Please I need an glupfile.js example for create .lcov files (coverage javascript and if its posible typescript coverage too) with your plugin sonar-web-frontend, thanks!!

Downgrade gulp dependency

  • downgrade gulp dependency by detecting if it is available
  • provide an access for pure Node.JS usage

Lower minimum node version?

Hi, thanks for getting this working properly with npm ๐Ÿ‘ . I was hoping to use version 3 in our CI pipeline on VS Team Services on their hosted agents (so I can't easily install different versions of software). They only have version 5.11.0 of node but it fails with error;

2016-12-06T20:55:29.9977163Z > sreporter
2016-12-06T20:55:29.9977163Z
2016-12-06T20:55:30.0936927Z C:\a\1\s\node_modules\sonar-web-frontend-reporters\bin\sreporter:10
2016-12-06T20:55:30.0936927Z class CLIEngine {
2016-12-06T20:55:30.0936927Z ^^^^^
2016-12-06T20:55:30.0946922Z
2016-12-06T20:55:30.0946922Z SyntaxError: Block-scoped declarations (let, const, function, class) not yet supported outside strict mode
2016-12-06T20:55:30.0946922Z at exports.runInThisContext (vm.js:53:16)
2016-12-06T20:55:30.0946922Z at Module._compile (module.js:387:25)
2016-12-06T20:55:30.0946922Z at Object.Module._extensions..js (module.js:422:10)
2016-12-06T20:55:30.0946922Z at Module.load (module.js:357:32)
2016-12-06T20:55:30.0946922Z at Function.Module._load (module.js:314:12)
2016-12-06T20:55:30.0946922Z at Function.Module.runMain (module.js:447:10)
2016-12-06T20:55:30.0946922Z at startup (node.js:148:18)
2016-12-06T20:55:30.0946922Z at node.js:405:3

I'm assuming this is due to node being < 6.9.1 .

SaveException: The file doesn't exist

Hello,

We are getting a following error when running the TS analysis for our project:

INFO: Sensor Lines Sensor
INFO: Sensor Lines Sensor (done) | time=0ms
INFO: Sensor TslintQualitySensor
INFO: ------------------------------------------------------------------------
INFO: EXECUTION FAILURE
INFO: ------------------------------------------------------------------------
INFO: Total time: 36.876s
INFO: Final Memory: 55M/511M
INFO: ------------------------------------------------------------------------
ERROR: Error during SonarQube Scanner execution
fr.sii.sonar.report.core.common.exception.SaveException: The file frontend\mobile\custom_typings\file.ts doesn't exist
	at fr.sii.sonar.report.core.common.util.FileUtil.checkMissing(FileUtil.java:239)
	at fr.sii.sonar.report.core.common.util.FileUtil.checkMissing(FileUtil.java:106)
	at fr.sii.sonar.report.core.quality.save.QualitySaver.save(QualitySaver.java:42)
	at fr.sii.sonar.report.core.quality.save.QualitySaver.save(QualitySaver.java:28)
	at fr.sii.sonar.report.core.common.ReportSensor.analyse(ReportSensor.java:106)
...

We have the following structure

\---sonar-project.properties
+---src
|   +---backend
|   +---frontend
|   |   +---mobile
|   |   |   +---custom_typings
|   |   |   |   \---file.ts
|   |   +---reports
|   |   |	+---sonar
|   |   |	|	\---tslint.json

This is how we configured the Gulp task:

gulp.task('sonar', function() {
    return SonarWebReporters.launchReporters({
        project: 'Project',
        css : false,
        js : false,
        eslint : false,
        eslint_angular: false,
        html: false,
        ts: {
          src: [
            '**/*.ts',
            '!node_modules/**/*',
            '!common/jspm_packages/**/*',
            '!mobile/jspm_packages/**/*',
            '!webortal/jspm_packages/**/*'
          ],
          report: "reports/sonar/tslint.json",
          rulesFile: "../tslint.json",
          task: "ci-tslint",
          linter: require("gulp-tslint")
        }
    });
});

and this is the output we get in reports/sonar/tslint.json (just part of it):

{
"language" : "reports/sonar/tslint.json",
"project" : "Project",
"projectPath" : ".",
"version" : "1.1.0",
"files" : [{
	"name" : "file.ts",
	"path" : "mobile\\custom_typings\\file.ts",
	"nbLines" : 1711,
	"nbComments" : 0,
	"nbCloc" : 1574,
	...

It seems that paths are somehow wrong but I cannot find any configuration which actually works. Am I doing something obviously wrong here?

Thanks in advance and best regards,

v3.0.0 not working with node v4.5.0

First of all, I would like to thank your job here. This plugins is really good.
I'm trying to use v3.0.0 with node v4.5.0 but seems not working as expected.
Even using the plugin with backward compatibility (ES5), the following error is displayed:

class SonarWebReporters {
^^^^^

SyntaxError: Block-scoped declarations (let, const, function, class) not yet supported outside strict mode
    at exports.runInThisContext (vm.js:53:16)
    at Module._compile (module.js:373:25)
    at Object.Module._extensions..js (module.js:416:10)
    at Module.load (module.js:343:32)
    at Function.Module._load (module.js:300:12)
    at Module.require (module.js:353:17)
    at require (internal/module.js:12:17)
    at Object.<anonymous> (/var/www/html/arquitetura/front-end-teste/node_modules/sonar-web-frontend-reporters/lib/api.js:2:27)
    at Module._compile (module.js:409:26)
    at Object.Module._extensions..js (module.js:416:10)

I've tried using require('sonar-web-frontend-reporters').ES5.Reporters or require('sonar-web-frontend-reporters/build/reporters) but both are causing errors. Using this second, the error is another:

TypeError: glob pattern string required
    at new Minimatch (/var/www/html/arquitetura/front-end-teste/node_modules/sonar-web-frontend-reporters/node_modules/glob/node_modules/minimatch/minimatch.js:116:11)
    at setopts (/var/www/html/arquitetura/front-end-teste/node_modules/sonar-web-frontend-reporters/node_modules/glob/common.js:118:20)
    at new Glob (/var/www/html/arquitetura/front-end-teste/node_modules/sonar-web-frontend-reporters/node_modules/glob/glob.js:135:3)
    at glob (/var/www/html/arquitetura/front-end-teste/node_modules/sonar-web-frontend-reporters/node_modules/glob/glob.js:75:10)
    at ESLintReporter.launch (/var/www/html/arquitetura/front-end-teste/node_modules/sonar-web-frontend-reporters/build/reporters/eslint.reporter.js:37:7)
    at SonarWebReporters.launch (/var/www/html/arquitetura/front-end-teste/node_modules/sonar-web-frontend-reporters/build/reporters.js:70:58)
    at /var/www/html/arquitetura/front-end-teste/node_modules/sonar-web-frontend-reporters/build/reporters.js:50:15
    at Array.forEach (native)
    at SonarWebReporters.launchReporters (/var/www/html/arquitetura/front-end-teste/node_modules/sonar-web-frontend-reporters/build/reporters.js:49:12)
    at Gulp.<anonymous> (/var/www/html/arquitetura/front-end-teste/gulpfile.js:21:21)

How to proceed ?

Error parsing JSON eslint-angular

Hi,
I have installed:

  • sonar v.4.5.7
  • sonar-web-frontend-plugin 2.1
  • sonar-web-frontend-reporters

When I configure gulp to start scan on a single js file, it generates a valid JSON report, but when I select all project, I have this error:

15:45:05.818 INFO - Sensor JsHintQualitySensor done: 38140 ms 15:45:05.834 INFO - Sensor EslintAngularQualitySensor... 15:45:06.115 ERROR - failed to parse json file. Cause: Unexpected end-of-input: expected close marker for ARRAY (from [Source: java.io.InputStreamReader@7444d60 d; line: 5, column: 19]) at [Source: java.io.InputStreamReader@7444d60d; line: 345187, column: 327] (thr ough reference chain: fr.sii.sonar.report.core.quality.domain.report.QualityRepo rt["files"]) 15:45:06.115 DEBUG - Release semaphore on project : org.sonar.api.resources.Proj ect@119655f1[id=6804,key=cdfe,qualifier=TRK], with key batch-cdfe INFO: ------------------------------------------------------------------------ INFO: EXECUTION FAILURE INFO: ------------------------------------------------------------------------ Total time: 2:27.374s Final Memory: 23M/191M INFO: ------------------------------------------------------------------------ ERROR: Error during Sonar runner execution org.sonar.runner.impl.RunnerException: Unable to execute Sonar at org.sonar.runner.impl.BatchLauncher$1.delegateExecution(BatchLauncher .java:91) at org.sonar.runner.impl.BatchLauncher$1.run(BatchLauncher.java:75) at java.security.AccessController.doPrivileged(Native Method) at org.sonar.runner.impl.BatchLauncher.doExecute(BatchLauncher.java:69) at org.sonar.runner.impl.BatchLauncher.execute(BatchLauncher.java:50) at org.sonar.runner.api.EmbeddedRunner.doExecute(EmbeddedRunner.java:102 ) at org.sonar.runner.api.Runner.execute(Runner.java:100) at org.sonar.runner.Main.executeTask(Main.java:70) at org.sonar.runner.Main.execute(Main.java:59) at org.sonar.runner.Main.main(Main.java:53) Caused by: java.lang.IllegalArgumentException: Cannot parse report E:\cdil0\cdfe 0_SRC\.\reports\sonar\eslint-angular.json at fr.sii.sonar.report.core.common.ReportSensor.analyse(ReportSensor.jav a:109) at org.sonar.batch.phases.SensorsExecutor.executeSensor(SensorsExecutor. java:79) at org.sonar.batch.phases.SensorsExecutor.execute(SensorsExecutor.java:7 0) at org.sonar.batch.phases.PhaseExecutor.execute(PhaseExecutor.java:119) at org.sonar.batch.scan.ModuleScanContainer.doAfterStart(ModuleScanConta iner.java:194) at org.sonar.api.platform.ComponentContainer.startComponents(ComponentCo ntainer.java:93) at org.sonar.api.platform.ComponentContainer.execute(ComponentContainer. java:78) at org.sonar.batch.scan.ProjectScanContainer.scan(ProjectScanContainer.j ava:233) at org.sonar.batch.scan.ProjectScanContainer.scanRecursively(ProjectScan Container.java:228) at org.sonar.batch.scan.ProjectScanContainer.doAfterStart(ProjectScanCon tainer.java:221) at org.sonar.api.platform.ComponentContainer.startComponents(ComponentCo ntainer.java:93) at org.sonar.api.platform.ComponentContainer.execute(ComponentContainer. java:78) at org.sonar.batch.scan.ScanTask.scan(ScanTask.java:64) at org.sonar.batch.scan.ScanTask.execute(ScanTask.java:51) at org.sonar.batch.bootstrap.TaskContainer.doAfterStart(TaskContainer.ja va:125) at org.sonar.api.platform.ComponentContainer.startComponents(ComponentCo ntainer.java:93) at org.sonar.api.platform.ComponentContainer.execute(ComponentContainer. java:78) at org.sonar.batch.bootstrap.BootstrapContainer.executeTask(BootstrapCon tainer.java:173) at org.sonar.batch.bootstrapper.Batch.executeTask(Batch.java:95) at org.sonar.batch.bootstrapper.Batch.execute(Batch.java:67) at org.sonar.runner.batch.IsolatedLauncher.execute(IsolatedLauncher.java :48) at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source) at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source) at java.lang.reflect.Method.invoke(Unknown Source) at org.sonar.runner.impl.BatchLauncher$1.delegateExecution(BatchLauncher .java:87) ... 9 more

My project has js files in multiple directories, please help me.

.eslintignore not read when generating eslint report

I have .eslintrc and also .eslintignore file.
The .eslintignore file is not being read by the sonar reporter. How do I specify ignorepaths/files in the .srreporterrc ?
I need to specify multiple files/folders hence a way to point to .eslintignore while running ESLint would help

HTMLHint JSON output can be invalid

Hi,

I currently have an issue where the HTML reporter is producing invalid JSON when the offending HTML is on a new line.

For example, this HTML:

<button class="cancelButton"
onclick="return false;">Cancel</button>

produces this invalid JSON in the report:

{
"line": 62,
"message": "Inline script [
onclick = 'return false;'] cannot be use.",
"description": "Inline script cannot be use.",
"rulekey": "inline-script-disabled",
"severity": "MINOR",
"reporter": "htmlhint",
"creationDate": 1472831618394
}

I'm also using your frontend plugin, which then throws an exception when it tries to parse this JSON.

I realise that this is due to the handling of the message in HTMLHint rule itself, but I don't think that's trying to create JSON, whereas the HTML reporter here is, hence why I'm reporting it here.

If you think it's an issue with the original HTMLHint, I will report it there instead.

Problem installing sonar-web-frontend-reporters off-line

Hi,
I have
node v6.9.5
npm v3.10.10

I need to install sonar web frontend reporters on an offline machine.
I alredy tried with npmbox and npmunbox, but I always have errors.
Now I'm trying with offline-npm.
when I try to pack the module with npm pack I have the folliwing error:

npm ERR! addLocal Could not install C:\Users\fguarino\AppData\Roaming\npm\node_m
odules\sonar-web-frontend-reporters
npm ERR! Windows_NT 6.1.7601
npm ERR! argv "C:\Program Files\nodejs\node.exe" "C:\Program Files\nodejs\
node_modules\npm\bin\npm-cli.js" "pack"
npm ERR! node v6.9.5
npm ERR! npm v3.10.10
npm ERR! code ELIFECYCLE
npm ERR! [email protected] prepublish: ./offline/offline-npm - -prepublish ; npm run-script build
npm ERR! Exit status 1
npm ERR!
npm ERR! Failed at the [email protected] prepublish script './o
ffline/offline-npm --prepublish ; npm run-script build'.
npm ERR! Make sure you have the latest version of node.js and npm installed.
npm ERR! If you do, this is most likely a problem with the sonar-web-frontend-re
porters package,
npm ERR! not with npm itself.
npm ERR! Tell the author that this fails on your system:
npm ERR! ./offline/offline-npm --prepublish ; npm run-script build
npm ERR! You can get information on how to open an issue for this project with:
npm ERR! npm bugs sonar-web-frontend-reporters
npm ERR! Or if that isn't available, you can get their info via:
npm ERR! npm owner ls sonar-web-frontend-reporters
npm ERR! There is likely additional logging output above.

npm ERR! Please include the following file with any support request:
npm ERR! C:\Users\fguarino\AppData\Roaming\npm\node_modules\sonar-web-fronte
nd-reporters\npm-debug.log

npm-debug.txt

could you please help me in some way?
Thanks
Francesca

Invalid JSON output

Hi

While checking out your plugin I had the same issue on the esLintReporter as mentioned in ticket #7 , the resolution you proposed in that ticket seems to be a valid fix. Would it be possible to update that Reporter as well (and possible other Reporters using the same logic)?

Severity rating on Sonar

Using sonar-web-frontend-reporters v3.0.0 with node v4.5.0, the eslint reports always are rating as info. How to change to major ?

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.