From 66400c07a153ae00a0ddecbab6868e8032062181 Mon Sep 17 00:00:00 2001 From: Gleb Bahmutov Date: Sun, 21 Dec 2014 15:23:45 -0500 Subject: [PATCH] adding linting via grunt --- .gitignore | 1 + .jshintrc | 74 ++++++++++++++++++++++++++++++++++++++ Gruntfile.js | 48 +++++++++++++++++++++++++ bower.json | 29 +++++++++++++++ eslint.json | 41 +++++++++++++++++++++ jscs.json | 15 ++++++++ ng-profile-local-digest.js | 2 ++ ng-profile-scope-method.js | 1 + ng-run-digest-cycle.js | 1 + package.json | 48 +++++++++++++++++++++++++ profile-method-call.js | 4 ++- time-method-call.js | 4 ++- 12 files changed, 266 insertions(+), 2 deletions(-) create mode 100644 .gitignore create mode 100644 .jshintrc create mode 100644 Gruntfile.js create mode 100644 bower.json create mode 100644 eslint.json create mode 100644 jscs.json create mode 100644 package.json diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..c2658d7 --- /dev/null +++ b/.gitignore @@ -0,0 +1 @@ +node_modules/ diff --git a/.jshintrc b/.jshintrc new file mode 100644 index 0000000..4a14ec0 --- /dev/null +++ b/.jshintrc @@ -0,0 +1,74 @@ +{ + "maxerr" : 50, + + "indent" : 2, + "bitwise" : true, + "camelcase" : true, + "curly" : true, + "eqeqeq" : true, + "forin" : true, + "immed" : false, + "latedef" : false, + "newcap" : true, + "noarg" : true, + "noempty" : true, + "nonew" : false, + "plusplus" : false, + "quotmark" : "single", + "undef" : true, + "unused" : true, + "strict" : false, + "trailing" : false, + "maxparams" : 4, + "maxdepth" : 3, + "maxstatements" : 20, + "maxcomplexity" : 20, + "maxlen" : 120, + + "asi" : false, + "boss" : false, + "debug" : false, + "eqnull" : false, + "es5" : false, + "esnext" : false, + "moz" : false, + "evil" : false, + "expr" : false, + "funcscope" : false, + "globalstrict" : false, + "iterator" : false, + "lastsemic" : false, + "laxbreak" : false, + "laxcomma" : false, + "loopfunc" : false, + "multistr" : false, + "proto" : false, + "scripturl" : false, + "smarttabs" : true, + "shadow" : false, + "sub" : false, + "supernew" : false, + "validthis" : false, + + "browser" : true, + "couch" : false, + "devel" : true, + "dojo" : false, + "jquery" : false, + "mootools" : false, + "node" : false, + "nonstandard" : false, + "prototypejs" : false, + "rhino" : false, + "worker" : false, + "wsh" : false, + "yui" : false, + + "nomen" : false, + "onevar" : false, + "passfail" : false, + "white" : false, + + "globals" : { + } +} diff --git a/Gruntfile.js b/Gruntfile.js new file mode 100644 index 0000000..1329024 --- /dev/null +++ b/Gruntfile.js @@ -0,0 +1,48 @@ +module.exports = function(grunt) { + 'use strict'; + + var sourceFiles = [ + '*.js', '!Gruntfile.js' + ]; + + grunt.initConfig({ + pkg: grunt.file.readJSON('package.json'), + + sync: { + all: { + options: { + sync: ['author', 'name', 'version', 'main', + 'private', 'license', 'keywords', 'homepage'], + } + } + }, + + jshint: { + all: sourceFiles, + options: { + jshintrc: '.jshintrc' + } + }, + + eslint: { + target: sourceFiles, + options: { + config: 'eslint.json', + rulesdir: ['./node_modules/eslint-rules'] + } + }, + + jscs: { + src: sourceFiles, + options: { + config: 'jscs.json' + } + } + }); + + var plugins = require('matchdep').filterDev('grunt-*'); + plugins.forEach(grunt.loadNpmTasks); + + grunt.registerTask('lint', ['jshint', 'eslint', 'jscs']); + grunt.registerTask('default', ['nice-package', 'deps-ok', 'sync', 'lint']); +}; diff --git a/bower.json b/bower.json new file mode 100644 index 0000000..bb0bc36 --- /dev/null +++ b/bower.json @@ -0,0 +1,29 @@ +{ + "name": "code-snippets", + "main": "turtles.js", + "version": "0.1.0", + "homepage": "https://github.com/bahmutov/code-snippets", + "license": "MIT", + "ignore": [ + "**/.*", + "node_modules", + "bower_components", + "test", + "tests", + "docs", + "Gruntfile.js", + "package.json", + "index.html" + ], + "author": "Gleb Bahmutov ", + "keywords": [ + "testing", + "test", + "exploratory", + "mock", + "chrome", + "devtools", + "code", + "snippets" + ] +} \ No newline at end of file diff --git a/eslint.json b/eslint.json new file mode 100644 index 0000000..b21096b --- /dev/null +++ b/eslint.json @@ -0,0 +1,41 @@ +{ + // this is JSON file, but ESLint allows C-style comments + + "env": { + "browser": true, + "node": false + }, + + // 0 - turn rule off + // 1 - rule generates warnings + // 2 - rule generates errors + "rules": { + "camelcase": 0, + "camel_case": 0, + "strict": 0, + "no-undef": 1, + "no-console": 0, + "no-unused-vars": 1, + "no-underscore-dangle": 1, + "quotes": [2, "single"], + "brace-style": [2, "1tbs"], + "eol-last": 1, + "semi": [2, "always"], + "no-extra-strict": 0, + "no-single-line-objects": 2, + "no-nested-ternary": 2, + "no-space-before-semi": 2, + "no-shadow": 2, + "no-undef-init": 2, + "no-undefined": 0, + "no-sequences": 2, + "no-for-loops": 2, + "no-process-exit": 0 + }, + + "globals": { + "navigator": true, + "console": true, + "Promise": true + } +} diff --git a/jscs.json b/jscs.json new file mode 100644 index 0000000..fe74262 --- /dev/null +++ b/jscs.json @@ -0,0 +1,15 @@ +{ + "requireCurlyBraces": true, + "requireDotNotation": true, + "requireSpaceAfterLineComment": true, + "validateQuoteMarks": "'", + "validateIndentation": 2, + "requireSpacesInFunctionExpression": { + "beforeOpeningCurlyBrace": true + }, + "requireSpacesInAnonymousFunctionExpression": { + "beforeOpeningRoundBrace": true, + "beforeOpeningCurlyBrace": true + }, + "requireSpacesInsideObjectBrackets": "all" +} diff --git a/ng-profile-local-digest.js b/ng-profile-local-digest.js index 951a6e9..7dccded 100644 --- a/ng-profile-local-digest.js +++ b/ng-profile-local-digest.js @@ -7,6 +7,8 @@ function profileDirectiveDigest(selector) { console.assert(selector && typeof selector === 'string', 'expected selector', selector); var el = document.querySelector(selector); console.assert(el, 'cannot find element with selector', selector); + + /* global angular */ var ngEl = angular.element(el); var scope = ngEl.scope() || ngEl.isolateScope(); console.assert(scope, 'cannot find scope from element', selector); diff --git a/ng-profile-scope-method.js b/ng-profile-scope-method.js index 219d070..3cd257c 100644 --- a/ng-profile-scope-method.js +++ b/ng-profile-scope-method.js @@ -12,6 +12,7 @@ var methodName = 'find'; var name = selector + ':' + methodName; + /* global angular */ var el = angular.element(document.getElementById(selector)); var scope = el.scope() || el.isolateScope(); console.assert(scope, 'cannot find scope from ' + name); diff --git a/ng-run-digest-cycle.js b/ng-run-digest-cycle.js index 2524269..32f92fe 100644 --- a/ng-run-digest-cycle.js +++ b/ng-run-digest-cycle.js @@ -1,2 +1,3 @@ // runs application digest cycle starting from root scope +/* global angular */ angular.element(document).injector().get('$rootScope').$apply(); diff --git a/package.json b/package.json new file mode 100644 index 0000000..8741001 --- /dev/null +++ b/package.json @@ -0,0 +1,48 @@ +{ + "name": "code-snippets", + "description": "Chrome DevTools code snippets ", + "version": "0.1.0", + "author": "Gleb Bahmutov ", + "bugs": { + "url": "https://github.com/bahmutov/code-snippets/issues" + }, + "contributors": [], + "dependencies": {}, + "devDependencies": { + "eslint-rules": "0.1.1", + "grunt": "0.4.5", + "grunt-contrib-jshint": "0.10.0", + "grunt-deps-ok": "0.5.1", + "grunt-eslint": "2.1.0", + "grunt-gh-pages": "0.9.1", + "grunt-jscs": "1.0.0", + "grunt-nice-package": "0.9.2", + "grunt-npm2bower-sync": "0.4.0", + "matchdep": "0.3.0", + "pre-git": "0.1.1" + }, + "engines": { + "node": "> 0.10.*" + }, + "homepage": "https://github.com/bahmutov/code-snippets", + "keywords": [ + "testing", + "test", + "exploratory", + "mock", + "chrome", + "devtools", + "code", + "snippets" + ], + "license": "MIT", + "main": "turtles.js", + "pre-commit": "npm test", + "repository": { + "type": "git", + "url": "git@github.com:bahmutov/code-snippets.git" + }, + "scripts": { + "test": "grunt" + } +} diff --git a/profile-method-call.js b/profile-method-call.js index 3d1b758..c0795cb 100644 --- a/profile-method-call.js +++ b/profile-method-call.js @@ -1,5 +1,7 @@ (function profileMethodCall() { - var object = primesApp; + var object = window.primesApp; + console.assert(object, 'cannot find object to profile'); + var methodName = 'findFirstPrimes'; var originalMethod = object[methodName]; console.assert(typeof originalMethod === 'function', 'cannot find method ' + methodName); diff --git a/time-method-call.js b/time-method-call.js index 3d74ec6..2983f88 100644 --- a/time-method-call.js +++ b/time-method-call.js @@ -1,5 +1,7 @@ (function timeMethodCall() { - var object = primesApp; + var object = window.primesApp; + console.assert(object, 'cannot find object to profile'); + var methodName = 'findFirstPrimes'; var originalMethod = object[methodName]; console.assert(typeof originalMethod === 'function', 'cannot find method ' + methodName);