Skip to content

Commit

Permalink
Replace JSCS/JSHint with ESLint & lint by editorconfig (#120)
Browse files Browse the repository at this point in the history
* CONTRIBUTING.md: JSHint => ESLint

* npm scripts: validate => lint

* replace JSHint with ESLint

* extend eslint-config-standard

* fix doc block

* abstract => strict equality

* uppercase constructor in private methods

* silence ESLint for `new Shower`

* fix variable names

* remove extra `new`

* silence ESLint for redeclare

* _remodeHandler => _removeHandler

* remove "EditorConfig is awesome"

* add editorconfig linting

* make lintspaces happy

* lint: ignore html comments

* allow nested folders

* Remove F5 “reload” shortcuts
  • Loading branch information
shvaikalesh committed Feb 2, 2017
1 parent af84857 commit e38a6be
Show file tree
Hide file tree
Showing 19 changed files with 94 additions and 56 deletions.
3 changes: 1 addition & 2 deletions .editorconfig
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
# EditorConfig is awesome: http://EditorConfig.org
root = true

[*]
Expand All @@ -9,5 +8,5 @@ trim_trailing_whitespace = true
insert_final_newline = true
charset = utf-8

[{package.json,.travis.yml}]
[{package.json,.eslintrc.json,.travis.yml}]
indent_size = 2
19 changes: 19 additions & 0 deletions .eslintrc.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
{
"extends": "standard",
"globals": {
"modules": false,
"shower": false
},
"rules": {
"indent": ["error", 4, {
"SwitchCase": 1
}],
"semi": ["error", "always"],
"space-before-function-paren": ["error", {
"anonymous": "always",
"named": "never"
}],
"operator-linebreak": ["error", "after"],
"padded-blocks": "off"
}
}
9 changes: 0 additions & 9 deletions .jscs.json

This file was deleted.

3 changes: 0 additions & 3 deletions .jshintignore

This file was deleted.

2 changes: 1 addition & 1 deletion CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ Fork needed repository, create a brach for each feature or issue you’re dealin

## Code style

Please preserve existing code style while contributing to Shower and be ready for code review by Shower maintainers. It’s strongly recommended to install [EditorConfig](http://editorconfig.org) extension to your editor and validate your JavaScript changes using [JSHint](http://jshint.com/).
Please preserve existing code style while contributing to Shower and be ready for code review by Shower maintainers. It’s strongly recommended to install [EditorConfig](http://editorconfig.org) extension to your editor and validate your JavaScript changes using [ESLint](http://eslint.org/).

## Language

Expand Down
42 changes: 36 additions & 6 deletions Gulpfile.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,9 @@

const gulp = require('gulp');
const concat = require('gulp-concat');
const eslint = require('gulp-eslint');
const insert = require('gulp-insert');
const jscs = require('gulp-jscs');
const lintspaces = require('gulp-lintspaces');
const mocha = require('gulp-mocha-phantomjs');
const rename = require('gulp-rename');
const uglify = require('gulp-uglify');
Expand All @@ -19,10 +20,34 @@ const banner = `/**
*/
`;

gulp.task('lint', () => {
return gulp.src('lib/*.js')
.pipe(jscs())
.pipe(jscs.reporter());
gulp.task('lint:ec', () => {
const sources = [
'.editorconfig',
'.gitignore',
'*.{json,yml,md}',
'lib/**',
'tests/**',
'wdio.conf.js',
];

const options = {
editorconfig: '.editorconfig',
ignores: [
'js-comments',
'html-comments',
],
};

return gulp.src(sources, { dot: true })
.pipe(lintspaces(options))
.pipe(lintspaces.reporter());
});

gulp.task('lint:js', () => {
return gulp.src('lib/**/*.js')
.pipe(eslint())
.pipe(eslint.format())
.pipe(eslint.failAfterError());
});

gulp.task('concat:lib', () => {
Expand All @@ -33,7 +58,7 @@ gulp.task('concat:lib', () => {
// Core.
'lib/init.js',
'lib/shower.js',
'lib/*/*.js',
'lib/**/*.js',

// Plugins.
'node_modules/shower-*/shower-*.js',
Expand Down Expand Up @@ -66,6 +91,11 @@ gulp.task('mocha', () => {
.pipe(mocha());
});

gulp.task('lint', [
'lint:ec',
'lint:js',
]);

gulp.task('dev', [
'lint',
'concat:lib',
Expand Down
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,11 @@ Core for the [Shower](https://github.com/shower/shower/) presentation engine. Do

Get the [Shower template](https://github.com/shower/shower/) where core is already included. Download the template [archive](http://shwr.me/shower.zip) or install the package:

npm install shower
npm install shower

You can also install core as a separate package:

npm install shower-core
npm install shower-core


## Development
Expand Down
16 changes: 8 additions & 8 deletions lib/emitter/Emitter.js
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ shower.modules.define('Emitter', [
off: function (types, callback, context, priority) {
priority = priority || 0;

if (typeof types == 'string') {
if (typeof types === 'string') {
this._removeListener(types, callback, context, priority);
} else {
for (var i = 0, l = types.length; i < l; i++) {
Expand Down Expand Up @@ -108,7 +108,7 @@ shower.modules.define('Emitter', [
var event = eventObject;
var listeners = this._listeners;

if (!event || typeof event.get != 'function') {
if (!event || typeof event.get !== 'function') {
event = this.createEventObject(eventType, eventObject, this._context);
}

Expand Down Expand Up @@ -141,7 +141,7 @@ shower.modules.define('Emitter', [
* @param {Emitter} parent
*/
setParent: function (parent) {
if (this._parent != parent) {
if (this._parent !== parent) {
this._parent = parent;
}
},
Expand Down Expand Up @@ -180,16 +180,16 @@ shower.modules.define('Emitter', [
for (var i = 0, l = listeners.length; i < l; i++) {
listener = listeners[i];

if (listener.callback == callback &&
listener.context == context &&
listener.priority == priority) {
if (listener.callback === callback &&
listener.context === context &&
listener.priority === priority) {

foundIndex = i;
}
}

if (foundIndex != -1) {
if (listeners.length == 1) {
if (foundIndex !== -1) {
if (listeners.length === 1) {
this._clearType(eventType);
} else {
listeners.splice(foundIndex, 1);
Expand Down
6 changes: 3 additions & 3 deletions lib/emitter/emitter.EventGroup.js
Original file line number Diff line number Diff line change
Expand Up @@ -97,9 +97,9 @@ shower.modules.define('emitter.EventGroup', [

_removeListener: function (type, callback, context) {
var index = this._listeners.indexOf(type, 0);
while (index != -1) {
if (this._listeners[index + 1] == callback &&
this._listeners[index + 2] == context) {
while (index !== -1) {
if (this._listeners[index + 1] === callback &&
this._listeners[index + 2] === context) {
this._listeners.splice(index, 3);

this.events.off(type, callback, context);
Expand Down
4 changes: 2 additions & 2 deletions lib/global/Plugins.js
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@ shower.modules.define('Plugins', [

_requireAndAdd: function (plugin) {
shower.modules.require(plugin.name, function (pluginClass) {
plugin.class = pluginClass;
plugin.Class = pluginClass;
this._plugins[plugin.name] = plugin;
this._instancePlugin(plugin);
}.bind(this));
Expand Down Expand Up @@ -131,7 +131,7 @@ shower.modules.define('Plugins', [
this._instances.push({
shower: shower,
plugin: plugin,
instance: new plugin.class(shower, options)
instance: new plugin.Class(shower, options)
});
},

Expand Down
1 change: 1 addition & 0 deletions lib/global/shower.global.js
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@ shower.modules.define('shower.global', [
initOptions = initOptions || {};

shower.modules.require(['Shower'], function (Shower) {
// eslint-disable-next-line no-new
new Shower(initOptions.container, initOptions.options);
});
},
Expand Down
10 changes: 5 additions & 5 deletions lib/options/options.Monitor.js
Original file line number Diff line number Diff line change
Expand Up @@ -58,11 +58,11 @@ shower.modules.define('options.Monitor', [
var fields = field;
for (var fieldName in fields) {
if (fields.hasOwnProperty(fieldName)) {
this._remodeHandler(fieldName, callback, context);
this._removeHandler(fieldName, callback, context);
}
}
} else {
this._remodeHandler(field, callback, context);
this._removeHandler(field, callback, context);
}

return this;
Expand All @@ -89,7 +89,7 @@ shower.modules.define('options.Monitor', [
}, this);
},

_addHandler: function (field, callback, context) {
_addHandler: function (fieldName, callback, context) {
var handler = {
callback: callback,
context: context
Expand All @@ -102,7 +102,7 @@ shower.modules.define('options.Monitor', [
}
},

_remodeHandler: function (field, callback, context) {
_removeHandler: function (field, callback, context) {
if (!this._fieldsHanders.hasOwnProperty(field)) {
throw new Error('Remove undefined handler for ' + field + ' field');
}
Expand All @@ -112,7 +112,7 @@ shower.modules.define('options.Monitor', [
return hander.callback === callback && hander.context === context;
})[0];

if (!hander) {
if (!handler) {
throw new Error('Hanlder for ' + field + ' not found.');
}

Expand Down
4 changes: 2 additions & 2 deletions lib/shower/Shower.js
Original file line number Diff line number Diff line change
Expand Up @@ -118,9 +118,9 @@ shower.modules.define('Shower', [
remove: function (slide) {
var slidePosition;

if (typeof slide == 'number') {
if (typeof slide === 'number') {
slidePosition = slide;
} else if (this._slides.indexOf(slide) != -1) {
} else if (this._slides.indexOf(slide) !== -1) {
slidePosition = this._slides.indexOf(slide);
} else {
throw new Error('Slide not found');
Expand Down
2 changes: 1 addition & 1 deletion lib/shower/shower.Container.js
Original file line number Diff line number Diff line change
Expand Up @@ -242,4 +242,4 @@ shower.modules.define('shower.Container', [
});

provide(Container);
});
});
2 changes: 1 addition & 1 deletion lib/shower/shower.Player.js
Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,7 @@ shower.modules.define('shower.Player', [
var slidesCount = this._shower.getSlidesCount();
var currentSlide = this._currentSlide;

if (index != this._currentSlideNumber && index < slidesCount && index >= 0) {
if (index !== this._currentSlideNumber && index < slidesCount && index >= 0) {
if (currentSlide && currentSlide.isActive()) {
currentSlide.deactivate();
}
Expand Down
4 changes: 2 additions & 2 deletions lib/slide/Slide.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ shower.modules.define('Slide', [
'util.Store',
'util.extend'
], function (provide, defaultOptions, EventEmitter, OptionsManager, Layout,
slideLayoutFactory, DataStore, extend) {
slideLayoutFactory, DataStore, extend) {

/**
* @typedef {object} HTMLElement
Expand Down Expand Up @@ -51,7 +51,7 @@ shower.modules.define('Slide', [

init: function () {
this.layout = typeof this._content === 'string' ?
new slideLayoutFactory.createLayout({
slideLayoutFactory.createLayout({
content: this._content
}) :
new Layout(this._content, this.options);
Expand Down
4 changes: 2 additions & 2 deletions lib/slide/slide.Layout.js
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ shower.modules.define('slide.Layout', [
},

setParent: function (parent) {
if (this._parent != parent) {
if (this._parent !== parent) {
this._clearListeners();

this._parent = parent;
Expand All @@ -77,7 +77,7 @@ shower.modules.define('slide.Layout', [
* @param {HTMLElement} parentElement
*/
setParentElement: function (parentElement) {
if (parentElement != this._parentElement) {
if (parentElement !== this._parentElement) {
this._parentElement = parentElement;
parentElement.appendChild(this._element);

Expand Down
2 changes: 1 addition & 1 deletion lib/utils/util.Store.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ shower.modules.define('util.Store', [
}
}

extend(Store.prototype, /**@lends Store.prototype */{
extend(Store.prototype, /** @lends Store.prototype */{
/**
* @param {string} key
* @param {object} [defaultValue] Default value which returns if data is not definded.
Expand Down
13 changes: 7 additions & 6 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -43,18 +43,19 @@
"devDependencies": {
"chai": "^3.5.0",
"chai-dom": "^1.4.3",
"eslint-config-standard": "^6.2.1",
"eslint-plugin-promise": "^3.4.0",
"eslint-plugin-standard": "^2.0.1",
"git-hooks": "^1.1.1",
"gulp": "^3.9.1",
"gulp-concat": "^2.6.1",
"gulp-eslint": "^3.0.1",
"gulp-insert": "^0.5.0",
"gulp-jscs": "^4.0.0",
"gulp-lintspaces": "^0.5.0",
"gulp-mocha-phantomjs": "^0.12.0",
"gulp-rename": "^1.2.2",
"gulp-uglify": "^2.0.0",
"gulp-webdriver": "^2.0.3",
"jscs": "^3.0.7",
"jscs-preset-loris": "^1.2.0",
"jshint": "^2.9.3",
"mocha": "^3.0.2",
"selenium-standalone": "^5.6.3",
"shower-next": "0.0.6",
Expand All @@ -69,9 +70,9 @@
},
"scripts": {
"prebuild": "selenium-standalone install",
"prepublish": "npm run build",
"prepublish": "gulp build",
"build": "gulp build",
"validate": "jshint . && gulp lint",
"lint": "gulp lint",
"test": "gulp test",
"report": "allure report generate -o allure-report allure-results && allure report open -o allure-report"
}
Expand Down

0 comments on commit e38a6be

Please sign in to comment.