Skip to content

Commit

Permalink
Merge pull request #62 from billybonks/remove-deprecations
Browse files Browse the repository at this point in the history
Remove deprecations
  • Loading branch information
billybonks authored Mar 14, 2018
2 parents 5ded1f1 + be1d881 commit aa4adb5
Show file tree
Hide file tree
Showing 5 changed files with 37 additions and 93 deletions.
59 changes: 13 additions & 46 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ const stylelint = require('stylelint');
const path = require('path');
const broccoliNodeInfo = require('broccoli-node-info');
const chalk = require('chalk');
const oldGenerator = require('./lib/test-generator-old');
const FACTORY_METHOD_USED = Symbol('create() factory method was used');

//Copied from stylelint, until style lint ignores files properly via node api
Expand Down Expand Up @@ -66,6 +65,7 @@ class StyleLinter extends Filter {
* @class
*/
constructor(inputNodes, options) {

super(inputNodes, options);

this.options = options || {linterConfig:{}};
Expand All @@ -77,24 +77,8 @@ class StyleLinter extends Filter {
'calling Stylelint() directly or using new Stylelint()');
}

if(options.consoleLogger){
console.warn('After 2.0 release "consoleLogger" propety will be removed in favour of stylelint formatter option');
}

this.compileOptions(options);
this.setSyntax(this.linterConfig);

if(typeof options['disableConsoleLogging'] !== 'undefined'){
console.warn('After 2.0 release "disableConsoleLogging" propety will be removed in favour of "log"');
this.log = !options['disableConsoleLogging'];
}

//TODO:remove this deprecation on v2 release
if(this.testGenerator === oldGenerator){
console.warn(`After 2.0 the default test generator will be removed in favour of a standard one, To migrate specify the "testingFramework" option in 2.0 it will default to qunit`);
}


}

static create(inputNode, _options){
Expand All @@ -105,18 +89,13 @@ class StyleLinter extends Filter {
}

compileOptions(options){
if(options.testingFramework){
options.testGenerator = require('./lib/test-generator');
}

/* Used to extract and delete options from input hash */
const availableOptions = [{name: 'onError'},
{name: 'disableTestGeneration'},
{name: 'testingFramework'},
{name: 'testingFramework', default:'qunit'},
{name: 'testFailingFiles'},
{name: 'testPassingFiles'},
{name: 'testGenerator', default: oldGenerator},
{name: 'consoleLogger', default: StyleLinter.prototype.consoleLogger},
{name: 'testGenerator', default: require('./lib/test-generator')},
{name: 'linterConfig', default: {}},
{name: 'log', default: true},
{name: 'console', default: console}];
Expand All @@ -127,7 +106,6 @@ class StyleLinter extends Filter {
let defaultValue = option.default || this[name];
this[name] = typeof options[name] === 'undefined' ? defaultValue : options[name];
}

if(typeof this.testFailingFiles === 'undefined' && typeof this.testPassingFiles === 'undefined' && typeof this.disableTestGeneration === 'undefined'){
this.testFailingFiles = true;
this.testPassingFiles = true;
Expand All @@ -136,9 +114,11 @@ class StyleLinter extends Filter {
this.testPassingFiles = typeof this.testPassingFiles === 'undefined' ? !this.disableTestGeneration : this.testPassingFiles;
}

if(this.testPassingFiles || this.testFailingFiles){
this.targetExtension = 'stylelint-test.js' ;
}
this.linterConfig = Object.assign({formatter: 'string'}, this.linterConfig);
this.linterConfig.files = null;

}
/**
* Sets the, file extensions that the broccoli plugin must parse
Expand All @@ -161,13 +141,7 @@ class StyleLinter extends Filter {
config.syntax = '';
}
extensions.push(targetExtension);
if(this.testPassingFiles || this.testFailingFiles) {
targetExtension = 'stylelint-test.js';
} else {
console.warn('After 2.0 release if not tests are disabled, broccoli-stylelint will not return the original files');
}
this.extensions = extensions;
this.targetExtension = targetExtension;
}

/** Filter Class Overrides **/
Expand Down Expand Up @@ -197,11 +171,13 @@ class StyleLinter extends Filter {
//sets the value to relative path otherwise it would be absolute path
results = self.processResults(results, relativePath);
if(results.errored && self.testFailingFiles) {
results.output = self.testGenerator(relativePath, results);
results.output = self.testGenerator(relativePath, results, this.testingFramework);
return results;
} else if(!results.errored && self.testPassingFiles) {
results.output = self.testGenerator(relativePath);
results.output = self.testGenerator(relativePath, results, this.testingFramework);
return results;
}
return results;
return '';
}).catch(err => {
console.error(chalk.red('======= Something went wrong running stylelint ======='));
if(err.code === 78){
Expand All @@ -224,14 +200,14 @@ class StyleLinter extends Filter {
* - Generate tests
* @override
*/
postProcess(results, relativePath) {
postProcess(results) {
if(results) {
if(results.errored){
if(this.onError) {
this.onError(results);
}
if(this.log) {
this.consoleLogger(results, relativePath);
this.console.log(results.log);
}
}
return results;
Expand Down Expand Up @@ -268,15 +244,6 @@ class StyleLinter extends Filter {
return results;
}

/**
* @method consoleLogger
*
* custom console logger
*/
consoleLogger(results) {
this.console.log(results.log);
}

}

module.exports = StyleLinter;
4 changes: 2 additions & 2 deletions jest-test.config.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
module.exports = {
displayName: 'test',
testRegex: '.*(test.js)',
testRegex: '.*(.test.js)',
watchPathIgnorePatterns: ['<rootDir>/tmp'],
testPathIgnorePatterns: ['tmp', 'node_modules'],
testPathIgnorePatterns: ['tmp', 'node_modules', '/__snapshots__/'],
coverageDirectory: 'coverage',
coverageReporters: ['lcov']
};
20 changes: 0 additions & 20 deletions lib/test-generator-old.js

This file was deleted.

19 changes: 19 additions & 0 deletions tests/__snapshots__/test.js.snap
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
// Jest Snapshot v1, https://goo.gl/fbAQLP

exports[`Broccoli StyleLint Plugin Generated Tests generates correct failing test string 1`] = `
"QUnit.module('Stylelint');
QUnit.test('has-errors.scss should pass stylelint', function(assert) {
assert.expect(1);
assert.ok(false, '1:15 Unexpected empty block (block-no-empty)\\\\n6:10 Expected \\\\\\\\\\"#000000\\\\\\\\\\" to be \\\\\\\\\\"black\\\\\\\\\\" (color-named)');
});
"
`;

exports[`Broccoli StyleLint Plugin Generated Tests generates correct passing test string 1`] = `
"QUnit.module('Stylelint');
QUnit.test('no-errors.scss should pass stylelint', function(assert) {
assert.expect(1);
assert.ok(false, 'no-errors.scss should pass stylelint');
});
"
`;
28 changes: 3 additions & 25 deletions tests/test.js
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ describe('Broccoli StyleLint Plugin', function() {
});

it('should log when log=true', co.wrap(function *() {
yield buildAndLint('tests/fixtures/has-errors', {disableConsoleLogging:false, console: fakeConsole});
yield buildAndLint('tests/fixtures/has-errors', {log:true, console: fakeConsole});
expect(fakeConsole.log).toHaveBeenCalled();
}));

Expand All @@ -114,11 +114,6 @@ describe('Broccoli StyleLint Plugin', function() {
let linter = StyleLinter.create('', options);
expect(linter.testGenerator).toEqual(require('../lib/test-generator'));
});

it('uses old geneator if testingFramework key is not present', function() {
let linter = StyleLinter.create('', {});
expect(linter.testGenerator).toEqual(require('../lib/test-generator-old'));
});
});


Expand Down Expand Up @@ -147,12 +142,6 @@ describe('Broccoli StyleLint Plugin', function() {
expect(linter.linterConfig).toEqual(linterConfig);
});

it('accepts a custom logger', co.wrap(function *() {
var spy = jest.fn();
yield buildAndLint('tests/fixtures/test-generation', {linterConfig:{syntax:'scss'}, log:true, consoleLogger:spy});
expect(spy).toHaveBeenCalled();
}));

describe('Tests', function () {

describe('Generate Tests', function(){
Expand Down Expand Up @@ -223,24 +212,13 @@ describe('Broccoli StyleLint Plugin', function() {
}));

it('generates correct failing test string', co.wrap(function *() {
var testAssertion = 'module(\'Style Lint\');\n'+
'test(\'has-errors.scss should pass stylelint\', function() {\n'+
' ok(false, \'1:15 Unexpected empty block (block-no-empty)\');\n'+
' ok(false, \'6:10 Expected \\"#000000\\" to be \\"black\\" (color-named)\');\n'+
'});\n';

let results = yield buildAndLint('tests/fixtures/has-errors', {testFailingFiles:true});
return expect(readTestFile(walkTestsOutputReadableTree(results))).toBe(testAssertion);
return expect(readTestFile(walkTestsOutputReadableTree(results))).toMatchSnapshot();
}));

it('generates correct passing test string', co.wrap(function *() {
var passedTestAssertion = 'module(\'Style Lint\');\n'+
'test(\'no-errors.scss should pass stylelint\', function() {\n'+
' ok(\'true , no-errors.scss passed stylelint\');\n'+
'});\n';

let results = yield buildAndLint('tests/fixtures/no-errors', {testPassingFiles:true});
return expect(readTestFile(walkTestsOutputReadableTree(results))).toBe(passedTestAssertion);
return expect(readTestFile(walkTestsOutputReadableTree(results))).toMatchSnapshot();
}));
});
});
Expand Down

0 comments on commit aa4adb5

Please sign in to comment.