Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remove Babel transpilation #88

Merged
merged 7 commits into from
Mar 30, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 0 additions & 3 deletions .babelrc

This file was deleted.

60 changes: 31 additions & 29 deletions lib/index.js
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
/* eslint global-require: 0, consistent-return: 0 */
'use strict';

const Filter = require('broccoli-persistent-filter');
const CLIEngine = require('eslint').CLIEngine;
const md5Hex = require('md5-hex');
const stringify = require('json-stable-stringify');
const path = require('path');
const escapeStringRegexp = require('escape-string-regexp');
const BUILD_DIR_REGEXP = new RegExp(`(${escapeStringRegexp(path.sep)})?build(${escapeStringRegexp(path.sep)})?$`);
const BUILD_DIR_REGEXP = new RegExp(`(${escapeStringRegexp(path.sep)})?lib(${escapeStringRegexp(path.sep)})?$`);

/**
* Calculates the severity of a eslint.linter.verify result
Expand All @@ -18,7 +18,9 @@ const BUILD_DIR_REGEXP = new RegExp(`(${escapeStringRegexp(path.sep)})?build(${e
* 1 indicates a warning-level result
* > 1 indicates an error-level result
*/
function getResultSeverity(resultMessages = []) {
function getResultSeverity() {
let resultMessages = arguments[0] || [];

return resultMessages.reduce((accumulatedSeverity, message) => {
const severity = message.severity || 0;

Expand Down Expand Up @@ -60,7 +62,9 @@ function resolveInputDirectory(inputNode) {
* @param {{config: String, rulesdir: String, format: String}} options Filter options
* @returns {EslintValidationFilter} Filter obconfig @constructor
*/
function EslintValidationFilter(inputNode, options = {}) {
function EslintValidationFilter(inputNode) {
let options = arguments[1] || {};

if (!(this instanceof EslintValidationFilter)) {
return new EslintValidationFilter(inputNode, options);
}
Expand Down Expand Up @@ -147,12 +151,12 @@ EslintValidationFilter.prototype.getDestFilePath = function getDestFilePath(rela
const filterPath = Filter.prototype.getDestFilePath.call(this, relativePath);
const fullPath = path.join(this.eslintrc, relativePath);

if(filterPath && !this.cli.isPathIgnored(fullPath)) {
if (filterPath && !this.cli.isPathIgnored(fullPath)) {
return filterPath;
} else {
return null
return null;
}
}
};

EslintValidationFilter.prototype.processString = function processString(content, relativePath) {
// verify file content
Expand Down Expand Up @@ -183,33 +187,31 @@ EslintValidationFilter.prototype.processString = function processString(content,
* @returns {Object} An object with an `.output` property, which will be
* used as the emitted file contents
*/
EslintValidationFilter.prototype.postProcess = function postProcess(results /* , relativePath */) {
let { report, output } = results;
EslintValidationFilter.prototype.postProcess = function postProcess(results /* , relativePath */) {
let report = results.report;

// if verification has result
if (report.results.length &&
report.results[0].messages.length) {
// if verification has result
if (report.results.length &&
report.results[0].messages.length) {

// log formatter output
this.console.log(this.formatter(report.results));
// log formatter output
this.console.log(this.formatter(report.results));

const throwOnWarn = !!this.internalOptions.throwOnWarn;
const throwOnError = !!this.internalOptions.throwOnError;
const throwOnWarn = !!this.internalOptions.throwOnWarn;
const throwOnError = !!this.internalOptions.throwOnError;

if (throwOnWarn || throwOnError) {
const resultSeverity = getResultSeverity(report.results[0].messages);
if (throwOnWarn || throwOnError) {
const resultSeverity = getResultSeverity(report.results[0].messages);

if (resultSeverity === 1 && throwOnWarn) {
throw new Error('rules violation with `warn` severity level');
}
if (resultSeverity === 1 && throwOnWarn) {
throw new Error('rules violation with `warn` severity level');
}

if (resultSeverity >= 2 && (throwOnWarn || throwOnError)) {
throw new Error('rules violation with `error` severity level');
}
}
}
if (resultSeverity >= 2 && (throwOnWarn || throwOnError)) {
throw new Error('rules violation with `error` severity level');
}
}
}

return {
output
};
return { output: results.output };
};
4 changes: 3 additions & 1 deletion lib/test-generators.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
'use strict';

const escape = require('js-string-escape');

function render(errors) {
Expand Down Expand Up @@ -51,4 +53,4 @@ function mocha(relativePath, errors, results) {
return output;
}

module.exports = {qunit, mocha};
module.exports = { qunit, mocha };
13 changes: 3 additions & 10 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,10 @@
"name": "broccoli-lint-eslint",
"version": "3.2.1",
"description": "broccoli filter that runs eslint",
"main": "build/index.js",
"main": "lib/index.js",
"scripts": {
"prebabelify": "rimraf build",
"babelify": "babel lib --out-dir build",
"prepublish": "npm run babelify && npm run lint",
"lint": "eslint .",
"test": "npm run babelify && mocha --compilers js:babel-register test/**/*test.js"
"test": "mocha test/*test.js test/**/*test.js"
},
"repository": {
"type": "git",
Expand All @@ -27,7 +24,7 @@
"broccoli-plugin"
],
"files": [
"build"
"lib"
],
"author": "Jonathan Kingston",
"license": "MIT",
Expand All @@ -44,17 +41,13 @@
"md5-hex": "^2.0.0"
},
"devDependencies": {
"babel-cli": "^6.4.5",
"babel-preset-es2015": "^6.3.13",
"babel-register": "^6.11.6",
"broccoli": "^0.16.9",
"broccoli-cli": "^1.0.0",
"broccoli-merge-trees": "^2.0.0",
"broccoli-source": "^1.1.0",
"broccoli-stew": "^1.2.0",
"chai": "^3.5.0",
"mocha": "^3.0.1",
"rimraf": "^2.5.1",
"sinon": "^2.0.0",
"sinon-chai": "^2.8.0"
}
Expand Down
33 changes: 13 additions & 20 deletions test/file-format-tests/test.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
/* eslint-disable no-unused-expressions */
const path = require('path');
const expect = require('../chai').expect;
const runEslint = require('../helpers/run-eslint');
const FILES_PATH = './formats';

const MESSAGES = {
DOUBLEQUOTE: 'Strings must use doublequote.',
Expand All @@ -20,24 +18,19 @@ describe('Supporting different config file formats', function() {
'yml'
];

return Promise.all(formats.map((format) => {

return new Promise((resolve) => {

it(`detects configuration files with the ${format} file type`, function() {
const filesPath = path.join(process.cwd(), 'test/file-format-tests/formats', format);

const promise = runEslint(filesPath, {
options: {
ignore: false
}
});

return promise.then(function({buildLog}) {
expect(buildLog, 'Reported erroroneous single-quoted strings').to.have.string(MESSAGES.DOUBLEQUOTE);
expect(buildLog, 'Reported erroroneous use of alert').to.have.string(MESSAGES.ALERT);
});
formats.forEach(format => {
it(`detects configuration files with the ${format} file type`, function() {
const filesPath = path.join(process.cwd(), 'test/file-format-tests/formats', format);

return runEslint(filesPath, {
options: {
ignore: false
}
}).then(result => {
expect(result.buildLog, 'Reported erroroneous single-quoted strings')
.to.have.string(MESSAGES.DOUBLEQUOTE)
.to.have.string(MESSAGES.ALERT);
});
});
}));
});
});
Loading