├── .gitignore ├── .jshintrc ├── .editorconfig ├── package.json ├── LICENSE ├── README.md └── index.js /.gitignore: -------------------------------------------------------------------------------- 1 | node_modules -------------------------------------------------------------------------------- /.jshintrc: -------------------------------------------------------------------------------- 1 | { 2 | "curly": true, 3 | "eqeqeq": true, 4 | "immed": true, 5 | "latedef": true, 6 | "newcap": true, 7 | "noarg": true, 8 | "sub": true, 9 | "undef": true, 10 | "boss": true, 11 | "eqnull": true, 12 | "node": true 13 | } -------------------------------------------------------------------------------- /.editorconfig: -------------------------------------------------------------------------------- 1 | root = true 2 | 3 | [*] 4 | indent_style = tab 5 | end_of_line = lf 6 | charset = utf-8 7 | trim_trailing_whitespace = true 8 | insert_final_newline = true 9 | 10 | [package.json] 11 | indent_style = space 12 | indent_size = 2 13 | 14 | [*.md] 15 | trim_trailing_whitespace = false -------------------------------------------------------------------------------- /package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "gulp-buddy.js", 3 | "version": "0.1.0", 4 | "description": "Gulp plugin for running buddy.js", 5 | "license": "MIT", 6 | "homepage": "https://github.com/Semigradsky/gulp-buddy.js", 7 | "repository": { 8 | "type": "git", 9 | "url": "https://github.com/Semigradsky/gulp-buddy.js.git" 10 | }, 11 | "author": { 12 | "name": "Dmitry Semigradsky", 13 | "email": "semigradskyd@gmail.com", 14 | "url": "https://github.com/Semigradsky" 15 | }, 16 | "engines": { 17 | "node": ">=0.10.0" 18 | }, 19 | "files": [ 20 | "index.js" 21 | ], 22 | "keywords": [ 23 | "gulpplugin", 24 | "magic", 25 | "number", 26 | "constant", 27 | "detection", 28 | "detect", 29 | "sniffer", 30 | "cli", 31 | "tool" 32 | ], 33 | "dependencies": { 34 | "gulp-util": "^3.0.0", 35 | "buddy.js": "^0.8.0", 36 | "through2": "^0.6.1", 37 | "chalk": "*" 38 | } 39 | } -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | The MIT License (MIT) 2 | 3 | Copyright (c) 2014 Dmitry Semigradsky 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in 13 | all copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 21 | THE SOFTWARE. -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # gulp-[buddy.js](https://github.com/danielstjules/buddy.js) 2 | 3 | > Gulp plugin for running buddy.js 4 | 5 | 6 | ## Install 7 | 8 | ```sh 9 | $ npm install --save-dev gulp-buddy.js 10 | ``` 11 | 12 | 13 | ## Usage 14 | 15 | ```js 16 | var gulp = require('gulp'); 17 | var buddyjs = require('gulp-buddy.js'); 18 | 19 | gulp.task('default', function () { 20 | return gulp.src('app.js') 21 | .pipe(buddyjs({ 22 | disableIgnore: true, 23 | reporter: 'detailed' 24 | })); 25 | }); 26 | ``` 27 | 28 | 29 | ### Options 30 | 31 | #### detectObjects 32 | Type: `Boolean` 33 | Default value: `false` 34 | 35 | Detect object expressions and properties. 36 | 37 | #### ignore 38 | Type: `Array` 39 | Default value: `[0, 1]` 40 | 41 | Numbers that will be ignored in the processing. 42 | 43 | #### disableIgnore 44 | Type: `Boolean` 45 | Default value: `false` 46 | 47 | Disables the ignore list. 48 | 49 | #### enforceConst 50 | Type: `Boolean` 51 | Default value: `false` 52 | 53 | Enforce literals to be declared with the `const` keyword. 54 | 55 | #### noColor 56 | Type: `Boolean` 57 | Default value: `false` 58 | 59 | Disables colors 60 | 61 | #### reporter 62 | Type: `String` 63 | Default value: `'simple'` 64 | 65 | Reporter to use. Options available are `'simple'`, `'json'` and `'detailed'`. 66 | -------------------------------------------------------------------------------- /index.js: -------------------------------------------------------------------------------- 1 | 'use strict'; 2 | 3 | var gutil = require('gulp-util'); 4 | var through = require('through2'); 5 | var chalk = require('chalk'); 6 | var Detector = require('buddy.js/lib/detector'); 7 | var reporters = require('buddy.js/lib/reporters'); 8 | 9 | function hook_stdout(callback) { 10 | process.stdout.write = (function(write) { 11 | return function(string, encoding, fd) { 12 | write.apply(process.stdout, arguments); 13 | callback(string, encoding, fd); 14 | }; 15 | })(process.stdout.write); 16 | } 17 | 18 | function checkOutput(output, reporter) { 19 | switch(reporter) { 20 | case "simple": 21 | return (output.indexOf("No magic numbers found") > -1); 22 | case "detailed": 23 | return (output.indexOf("No magic numbers found") > -1); 24 | case "json": 25 | return output === "[]"; 26 | default: 27 | return true; 28 | } 29 | } 30 | 31 | module.exports = function(options) { 32 | var paths = []; 33 | 34 | options = options || {}; 35 | options.ignore = options.ignore || [0, 1]; 36 | options.disableIgnore = options.disableIgnore || false; 37 | options.reporter = options.reporter || "simple"; 38 | options.enforceConst = options.enforceConst || false; 39 | options.noColor = options.noColor || false; 40 | 41 | if (options.noColor) { 42 | chalk.enabled = false; 43 | } 44 | 45 | var ignore = options.disableIgnore ? [] : options.ignore; 46 | 47 | return through.obj(function (file, enc, cb) { 48 | if (file.isNull()) { 49 | cb(null, file); 50 | return; 51 | } 52 | 53 | paths.push(file.path); 54 | cb(null, file); 55 | }, function (cb) { 56 | if (paths.length === 0) { 57 | cb(); 58 | return; 59 | } 60 | 61 | var detector = new Detector(paths, options.enforceConst, ignore); 62 | var reporter = new reporters[options.reporter](detector); 63 | 64 | var output = ""; 65 | hook_stdout(function(string, encoding, fd) { 66 | output += string; 67 | }); 68 | 69 | detector.run().then(function() { 70 | if (checkOutput(output, options.reporter)) { 71 | cb(); 72 | } 73 | return; 74 | }, function(e) { 75 | throw new gutil.PluginError('gulp-buddy.js', e); 76 | }); 77 | }); 78 | 79 | }; 80 | --------------------------------------------------------------------------------