Skip to content

Commit

Permalink
Linting: add grunt lint task, .eslintrc and .editorconfig (processing…
Browse files Browse the repository at this point in the history
…#186)

* add lint task, .eslintrc, .editorconfig. lint src

* lint: check for semicolons and no-extra-semicolons
  • Loading branch information
therewasaguy authored Jun 29, 2017
1 parent ba24f83 commit b06b851
Show file tree
Hide file tree
Showing 31 changed files with 1,130 additions and 1,097 deletions.
17 changes: 17 additions & 0 deletions .editorconfig
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
# EditorConfig: http://EditorConfig.org

# Top-most EditorConfig file
root = true

# Rules for JavaScript files:

[*.js]
# 2 space indentation
indent_style = space
indent_size = 2
# No trailing spaces
trim_trailing_whitespace = true
# Unix-style newlines
end_of_line = lf
# Newline ending every file
insert_final_newline = true
34 changes: 6 additions & 28 deletions Gruntfile.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,32 +2,12 @@ module.exports = function(grunt) {

grunt.initConfig({
pkg: grunt.file.readJSON('package.json'),
jshint: {
build: {
options: {jshintrc: '.jshintrc'},
src: ['Gruntfile.js']
},

// Configure style consistency
eslint: {
source: {
options: {jshintrc: 'src/.jshintrc'},
options: {configFile: './src/.eslintrc'},
src: ['src/**/*.js']
},
test: {
options: {jshintrc: 'test/.jshintrc'},
src: ['test/unit/**/*.js']
}
},
yuidoc: {
compile: {
name: '<%= pkg.name %>',
description: '<%= pkg.description %>',
version: '<%= pkg.version %>',
url: '<%= pkg.homepage %>',
options: {
paths: ['src/'],
//helpers: [],
themedir: 'docs/yuidoc-p5-theme/',
outdir: 'docs/reference/'
}
}
},
watch: {
Expand Down Expand Up @@ -171,14 +151,12 @@ module.exports = function(grunt) {


grunt.loadNpmTasks('grunt-contrib-requirejs');
grunt.loadNpmTasks('grunt-contrib-yuidoc');
grunt.registerTask('yui', ['yuidoc']);

grunt.loadNpmTasks('grunt-contrib-jshint');
grunt.loadNpmTasks('grunt-eslint');
grunt.loadNpmTasks('grunt-contrib-watch');
grunt.loadNpmTasks('grunt-contrib-connect');
grunt.loadNpmTasks('grunt-open');

grunt.registerTask('lint', ['eslint:source']);
grunt.registerTask('default', ['requirejs']);
grunt.registerTask('dev', ['connect','requirejs', 'watch']);
grunt.registerTask('serve', 'connect:server:keepalive');
Expand Down
13 changes: 5 additions & 8 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,17 +9,14 @@
"devDependencies": {
"almond": "~0.2.7",
"amdclean": "~2.0",
"grunt": "~0.4.2",
"grunt": "~0.4.5",
"grunt-cli": "^0.1.13",
"grunt-contrib-connect": "^1.0.2",
"grunt-contrib-jshint": "~0.6.3",
"grunt-contrib-nodeunit": "~0.2.0",
"grunt-contrib-requirejs": "~0.4.1",
"grunt-contrib-sass": "~0.7.2",
"grunt-contrib-watch": "~0.5.3",
"grunt-contrib-yuidoc": "0.5.2",
"grunt-mocha": "~0.4.6",
"grunt-open": "^0.2.3",
"phantomjs": "~1.9.2-4"
"grunt-eslint": "^20.0.0",
"grunt-mocha": "^1.0.4",
"grunt-open": "^0.2.3"
},
"dependencies": {
"tone": "therewasaguy/tone.js#p5-dev"
Expand Down
78 changes: 78 additions & 0 deletions src/.eslintrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,78 @@
{
"env": {
"jasmine": true,
"node": true,
"mocha": true,
"browser": true,
"builtin": true
},
"globals": {
"p5": true,
"define": true,
"Float32Array": true,
"Uint8Array": true
},
"rules": {
"block-scoped-var": 0,
"camelcase": 0,
"comma-style": [
2,
"last"
],
"dot-notation": [
2,
{
"allowKeywords": true
}
],
"eqeqeq": [
2,
"allow-null"
],
"eol-last": ["error", "always"],
"guard-for-in": 2,
"indent": ["error", 2, { "SwitchCase": 1 }],
"max-len": [1, 120, 2, {ignoreComments: true}],
"new-cap": 2,
"no-caller": 2,
"no-cond-assign": [
2,
"except-parens"
],
"no-debugger": 2,
"no-empty": 2,
"no-eval": 2,
"no-extend-native": 2,
"no-extra-parens": 2,
"no-extra-semi": 2,
"no-irregular-whitespace": 2,
"no-trailing-spaces": 2,
"no-iterator": 2,
"no-loop-func": 0,
"no-multiple-empty-lines": ["error", { "max": 2, "maxEOF": 1 }],
"no-multi-str": 2,
"no-new": 2,
"no-plusplus": 0,
"no-proto": 2,
"no-script-url": 2,
"no-sequences": 2,
"no-shadow": 2,
"no-undef": 2,
"no-unused-vars": 2,
"no-with": 2,
"quotes": [
2,
"single"
],
"semi": [
2
],
"space-before-blocks": "error",
"strict": 2,
"valid-typeof": 2,
"wrap-iife": [
2,
"inside"
]
}
}
24 changes: 0 additions & 24 deletions src/.jshintrc

This file was deleted.

21 changes: 11 additions & 10 deletions src/amplitude.js
Original file line number Diff line number Diff line change
@@ -1,12 +1,13 @@
'use strict';

define(function (require) {
'use strict';
var p5sound = require('master');

/**
* Amplitude measures volume between 0.0 and 1.0.
* Listens to all p5sound by default, or use setInput()
* to listen to a specific sound source. Accepts an optional
* smoothing value, which defaults to 0.
* smoothing value, which defaults to 0.
*
* @class p5.Amplitude
* @constructor
Expand All @@ -16,7 +17,7 @@ define(function (require) {
* @example
* <div><code>
* var sound, amplitude, cnv;
*
*
* function preload(){
* sound = loadSound('assets/beat.mp3');
* }
Expand Down Expand Up @@ -165,7 +166,7 @@ define(function (require) {
}
};

p5.Amplitude.prototype.disconnect = function(unit) {
p5.Amplitude.prototype.disconnect = function() {
this.output.disconnect();
};

Expand All @@ -182,7 +183,7 @@ define(function (require) {

for (var i = 0; i < bufLength; i++) {
x = inputBuffer[i];
if (this.normalize){
if (this.normalize) {
total += Math.max(Math.min(x/this.volMax, 1), -1);
sum += Math.max(Math.min(x/this.volMax, 1), -1) * Math.max(Math.min(x/this.volMax, 1), -1);
}
Expand Down Expand Up @@ -231,7 +232,7 @@ define(function (require) {
* function preload(){
* sound = loadSound('assets/beat.mp3');
* }
* function setup() {
* function setup() {
* amplitude = new p5.Amplitude();
* sound.play();
* }
Expand All @@ -248,7 +249,7 @@ define(function (require) {
* </code></div>
*/
p5.Amplitude.prototype.getLevel = function(channel) {
if (typeof(channel) !== 'undefined') {
if (typeof channel !== 'undefined') {
if (this.normalize) {
return this.stereoVolNorm[channel];
} else {
Expand Down Expand Up @@ -277,7 +278,7 @@ define(function (require) {
* @param {boolean} [boolean] set normalize to true (1) or false (0)
*/
p5.Amplitude.prototype.toggleNormalize = function(bool) {
if (typeof(bool) === 'boolean'){
if (typeof bool === 'boolean') {
this.normalize = bool;
}
else {
Expand All @@ -286,7 +287,7 @@ define(function (require) {
};

/**
* Smooth Amplitude analysis by averaging with the last analysis
* Smooth Amplitude analysis by averaging with the last analysis
* frame. Off by default.
*
* @method smooth
Expand All @@ -312,4 +313,4 @@ define(function (require) {
this.output = undefined;
};

});
});
5 changes: 2 additions & 3 deletions src/app.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
define(function (require) {
'use strict';

'use strict';
define(function (require) {

var p5SOUND = require('sndcore');
require('master');
Expand All @@ -16,7 +16,6 @@ define(function (require) {
require('pulse');
require('noise');
require('audioin');
// require('effect');
require('filter');
require('delay');
require('reverb');
Expand Down
Loading

0 comments on commit b06b851

Please sign in to comment.