UNPKG

kitchensink

Version:

Dispatch's awesome components and style guide

1,414 lines (1,204 loc) 4.18 MB
(function(f){if(typeof exports==="object"&&typeof module!=="undefined"){module.exports=f()}else if(typeof define==="function"&&define.amd){define([],f)}else{var g;if(typeof window!=="undefined"){g=window}else if(typeof global!=="undefined"){g=global}else if(typeof self!=="undefined"){g=self}else{g=this}g.JscsStringChecker = f()}})(function(){var define,module,exports;return (function e(t,n,r){function s(o,u){if(!n[o]){if(!t[o]){var a=typeof require=="function"&&require;if(!u&&a)return a(o,!0);if(i)return i(o,!0);var f=new Error("Cannot find module '"+o+"'");throw f.code="MODULE_NOT_FOUND",f}var l=n[o]={exports:{}};t[o][0].call(l.exports,function(e){var n=t[o][1][e];return s(n?n:e)},l,l.exports,e,t,n,r)}return n[o].exports}var i=typeof require=="function"&&require;for(var o=0;o<r.length;o++)s(r[o]);return s})({1:[function(require,module,exports){ var assert = require('assert'); var path = require('path'); var minimatch = require('minimatch'); var defaults = { cwd: '.', maxErrors: 50 }; var _ = require('lodash'); var BUILTIN_OPTIONS = { plugins: true, preset: true, excludeFiles: true, additionalRules: true, fileExtensions: true, extract: true, maxErrors: true, configPath: true, esnext: true, es3: true, esprima: true, esprimaOptions: true, errorFilter: true, verbose: true, fix: true }; /** * JSCS Configuration. * Browser/Rhino-compatible. * * @name Configuration */ function Configuration() { /** * List of the registered (not used) presets. * * @protected * @type {Object} */ this._presets = {}; /** * Name of the preset (if used). * * @protected * @type {String|null} */ this._presetName = null; /** * List of loaded presets. * * @protected * @type {String|null} */ this._loadedPresets = []; /** * List of rules instances. * * @protected * @type {Object} */ this._rules = {}; /** * List of configurated rule instances. * * @protected * @type {Object} */ this._ruleSettings = {}; /** * List of configured rules. * * @protected * @type {Array} */ this._configuredRules = []; /** * List of unsupported rules. * * @protected * @type {Array} */ this._unsupportedRuleNames = []; /** * File extensions that would be checked. * * @protected * @type {Array} */ this._fileExtensions = []; /** * Default file extensions that would be checked. * * @protected * @type {Array} */ this._defaultFileExtensions = ['.js']; /** * Exclusion masks. * * @protected * @type {Array} */ this._excludedFileMasks = []; /** * Default exclusion masks, will be rewritten if user has their own masks. * * @protected * @type {Array} */ this._defaultExcludedFileMasks = ['.git/**', 'node_modules/**']; /** * List of existing files that falls under exclusion masks. * * @protected * @type {Array} */ this._excludedFileMatchers = []; /** * Extraction masks. * * @protected * @type {Array} */ this._extractFileMasks = []; /** * Default extractions masks. * * @protected * @type {Array} */ this._defaultExtractFileMasks = ['**/*.+(htm|html|xhtml)']; /** * List of file matchers from which to extract JavaScript. * * @protected * @type {Array} */ this._extractFileMatchers = []; /** * Maxixum amount of error that would be reportered. * * @protected * @type {Number} */ this._maxErrors = defaults.maxErrors; /** * JSCS CWD. * * @protected * @type {String} */ this._basePath = defaults.cwd; /** * List of overrided options (usually from CLI). * * @protected * @type {Object} */ this._overrides = {}; /** * Is "esnext" mode enabled? * * @protected * @type {Boolean} */ this._esnextEnabled = false; /** * Is "ES3" mode enabled?. * * @protected * @type {Boolean} */ this._es3Enabled = false; /** * Custom version of esprima if specified. * * @protected * @type {Object|null} */ this._esprima = null; /** * Options that would be passed to esprima. * * @protected * @type {Object} */ this._esprimaOptions = {}; /** * A filter function that determines whether or not to report an error. * * @protected * @type {Function|null} */ this._errorFilter = null; /** * Should we show rule names in error output? * * @protected * @type {Boolean} */ this._verbose = false; } /** * Load settings from a configuration. * * @param {Object} config */ Configuration.prototype.load = function(config) { // Apply all the options this._processConfig(config); // Load and apply all the rules this._useRules(); }; /** * Returns resulting configuration after preset is applied and options are processed. * * @return {Object} */ Configuration.prototype.getProcessedConfig = function() { var result = {}; Object.keys(this._ruleSettings).forEach(function(key) { result[key] = this._ruleSettings[key]; }, this); result.excludeFiles = this._excludedFileMasks; result.fileExtensions = this._fileExtensions; result.extract = this._extractFileMasks; result.maxErrors = this._maxErrors; result.preset = this._presetName; result.esnext = this._esnextEnabled; result.es3 = this._es3Enabled; result.esprima = this._esprima; result.esprimaOptions = this._esprimaOptions; result.errorFilter = this._errorFilter; return result; }; /** * Returns list of configured rules. * * @returns {Rule[]} */ Configuration.prototype.getConfiguredRules = function() { return this._configuredRules; }; /** * Returns configured rule. * * @returns {Rule | null} */ Configuration.prototype.getConfiguredRule = function(name) { return this._configuredRules.filter(function(rule) { return rule.getOptionName() === name; })[0] || null; }; /** * Returns the list of unsupported rule names. * * @return {String[]} */ Configuration.prototype.getUnsupportedRuleNames = function() { return this._unsupportedRuleNames; }; /** * Returns excluded file mask list. * * @returns {String[]} */ Configuration.prototype.getExcludedFileMasks = function() { return this._excludedFileMasks; }; /** * Returns `true` if specified file path is excluded. * * @param {String} filePath * @returns {Boolean} */ Configuration.prototype.isFileExcluded = function(filePath) { filePath = path.resolve(filePath); return this._excludedFileMatchers.some(function(matcher) { return matcher.match(filePath); }); }; /** * Returns file extension list. * * @returns {String[]} */ Configuration.prototype.getFileExtensions = function() { return this._fileExtensions; }; /** * Returns extract file masks. * * @returns {String[]} */ Configuration.prototype.getExtractFileMasks = function() { return this._extractFileMasks; }; /** * Should filePath to be extracted? * * @returns {Boolean} */ Configuration.prototype.shouldExtractFile = function(filePath) { filePath = path.resolve(filePath); return this._extractFileMatchers.some(function(matcher) { return matcher.match(filePath); }); }; /** * Returns maximal error count. * * @returns {Number|null} */ Configuration.prototype.getMaxErrors = function() { return this._maxErrors; }; /** * Getter "fix" option value. * * @return {Boolean} */ Configuration.prototype.getFix = function() { return !!this._fix; }; /** * Returns `true` if `esnext` option is enabled. * * @returns {Boolean} */ Configuration.prototype.isESNextEnabled = function() { return this._esnextEnabled; }; /** * Returns `true` if `es3` option is enabled. * * @returns {Boolean} */ Configuration.prototype.isES3Enabled = function() { return this._es3Enabled; }; /** * Returns `true` if `esprima` option is not null. * * @returns {Boolean} */ Configuration.prototype.hasCustomEsprima = function() { return !!this._esprima; }; /** * Returns the custom esprima parser. * * @returns {Object|null} */ Configuration.prototype.getCustomEsprima = function() { return this._esprima; }; /** * Returns verbose option. * * @returns {Object|null} */ Configuration.prototype.getVerbose = function() { return this._verbose || false; }; /** * Returns custom Esprima options. * * @returns {Object} */ Configuration.prototype.getEsprimaOptions = function() { return this._esprimaOptions; }; /** * Returns the loaded error filter. * * @returns {Function|null} */ Configuration.prototype.getErrorFilter = function() { return this._errorFilter; }; /** * Returns base path. * * @returns {String} */ Configuration.prototype.getBasePath = function() { return this._basePath; }; /** * Overrides specified settings. * * @param {String} overrides */ Configuration.prototype.override = function(overrides) { Object.keys(overrides).forEach(function(key) { this._overrides[key] = overrides[key]; }, this); }; /** * returns options, but not rules, from the provided config * * @param {Object} config * @returns {Object} */ Configuration.prototype._getOptionsFromConfig = function(config) { return Object.keys(config).reduce(function(options, key) { if (BUILTIN_OPTIONS[key]) { options[key] = config[key]; } return options; }, {}); }; /** * Processes configuration and returns config options. * * @param {Object} config */ Configuration.prototype._processConfig = function(config) { var overrides = this._overrides; var currentConfig = {}; // Copy configuration so original config would be intact copyConfiguration(config, currentConfig); // Override the properties copyConfiguration(overrides, currentConfig); // NOTE: options is a separate object to ensure that future options must be added // to BUILTIN_OPTIONS to work, which also assures they aren't mistaken for a rule var options = this._getOptionsFromConfig(currentConfig); // Base path if (this._basePath === defaults.cwd && options.configPath) { assert( typeof options.configPath === 'string', '`configPath` option requires string value' ); this._basePath = path.dirname(options.configPath); } if (options.hasOwnProperty('plugins')) { assert(Array.isArray(options.plugins), '`plugins` option requires array value'); options.plugins.forEach(function(plugin) { this._loadPlugin(plugin, options.configPath); }, this); } if (options.hasOwnProperty('additionalRules')) { assert(Array.isArray(options.additionalRules), '`additionalRules` option requires array value'); options.additionalRules.forEach(function(rule) { this._loadAdditionalRule(rule, options.configPath); }, this); } if (options.hasOwnProperty('extract')) { this._loadExtract(options.extract); } if (options.hasOwnProperty('fileExtensions')) { this._loadFileExtensions(options.fileExtensions); // Set default extensions if there is no presets that could define their own } else if (!options.hasOwnProperty('preset')) { this._loadFileExtensions(this._defaultFileExtensions); } if (options.hasOwnProperty('excludeFiles')) { this._loadExcludedFiles(options.excludeFiles); // Set default masks if there is no presets that could define their own } else if (!options.hasOwnProperty('preset')) { this._loadExcludedFiles(this._defaultExcludedFileMasks); } if (options.hasOwnProperty('fix')) { this._loadFix(options.fix); } this._loadMaxError(options); if (options.hasOwnProperty('esnext')) { this._loadESNext(options.esnext); } if (options.hasOwnProperty('es3')) { this._loadES3(options.es3); } if (options.hasOwnProperty('esprima')) { this._loadEsprima(options.esprima, options.configPath); } if (options.hasOwnProperty('esprimaOptions')) { this._loadEsprimaOptions(options.esprimaOptions); } if (options.hasOwnProperty('errorFilter')) { this._loadErrorFilter(options.errorFilter, options.configPath); } if (options.hasOwnProperty('verbose')) { this._loadVerbose(options.verbose); } // Apply presets if (options.hasOwnProperty('preset')) { this._loadPreset(options.preset, options.configPath); } this._loadRules(currentConfig); }; /** * Loads plugin data. * * @param {function(Configuration)} plugin * @protected */ Configuration.prototype._loadPlugin = function(plugin) { assert(typeof plugin === 'function', '`plugin` should be a function'); plugin(this); }; /** * Load rules. * * @param {Object} config * @protected */ Configuration.prototype._loadRules = function(config) { Object.keys(config).forEach(function(key) { // Only rules should be processed if (BUILTIN_OPTIONS[key]) { return; } if (this._rules[key]) { var optionValue = config[key]; // Disable rule it it equals "false" or "null" if (optionValue === null || optionValue === false) { delete this._ruleSettings[key]; } else { this._ruleSettings[key] = config[key]; } } else if (this._unsupportedRuleNames.indexOf(key) === -1) { this._unsupportedRuleNames.push(key); } }, this); }; /** * Loads an error filter. * * @param {Function|null} errorFilter * @protected */ Configuration.prototype._loadErrorFilter = function(errorFilter) { assert( typeof errorFilter === 'function' || errorFilter === null, '`errorFilter` option requires a function or null value' ); this._errorFilter = errorFilter; }; /** * Loads verbose option. * * @param {Boolean|null} verbose * @protected */ Configuration.prototype._loadVerbose = function(verbose) { assert( typeof verbose === 'boolean' || verbose === null, '`verbose` option requires a boolean or null value' ); this._verbose = verbose; }; /* * Load "esnext" option. * * @param {Boolean} esnext * @protected */ Configuration.prototype._loadESNext = function(esnext) { assert( typeof esnext === 'boolean' || esnext === null, '`esnext` option requires boolean or null value' ); this._esnextEnabled = Boolean(esnext); }; /** * Load "es3" option. * * @param {Boolean} es3 * @protected */ Configuration.prototype._loadES3 = function(es3) { assert( typeof es3 === 'boolean' || es3 === null, '`es3` option requires boolean or null value' ); this._es3Enabled = Boolean(es3); }; /** * Load "maxError" option. * * @param {Object} options * @protected */ Configuration.prototype._loadMaxError = function(options) { // If "fix" option is enabled, set to Inifinity, otherwise this option // doesn't make sense with "fix" conjunction if (this._fix === true) { this._maxErrors = Infinity; return; } if (!options.hasOwnProperty('maxErrors')) { return; } var maxErrors = options.maxErrors === null ? null : Number(options.maxErrors); assert( maxErrors === -1 || maxErrors > 0 || maxErrors === null, '`maxErrors` option requires -1, null value or positive number' ); this._maxErrors = maxErrors; }; /** * Load "fix" option. * * @param {Boolean|null} fix * @protected */ Configuration.prototype._loadFix = function(fix) { fix = fix === null ? false : fix; assert( typeof fix === 'boolean', '`fix` option requires boolean or null value' ); this._fix = fix; }; /** * Loads a custom esprima. * * @param {Object|null} esprima * @protected */ Configuration.prototype._loadEsprima = function(esprima) { assert( (esprima && typeof esprima.parse === 'function') || esprima === null, '`esprima` option requires a null value or an object with a parse function' ); this._esprima = esprima; }; /** * Load preset. * * @param {Object} preset * @protected */ Configuration.prototype._loadPreset = function(preset) { if (this._loadedPresets.indexOf(preset) > -1) { return; } // Do not keep adding preset from CLI (#2087) delete this._overrides.preset; this._loadedPresets.push(preset); // If preset is loaded from another preset - preserve the original name if (!this._presetName) { this._presetName = preset; } assert(typeof preset === 'string', '`preset` option requires string value'); var presetData = this._presets[preset]; assert(Boolean(presetData), 'Preset "' + preset + '" does not exist'); // Process config from the preset this._processConfig(this._presets[preset]); }; /** * Load file extensions. * * @param {String|Array} extensions * @protected */ Configuration.prototype._loadFileExtensions = function(extensions) { assert( typeof extensions === 'string' || Array.isArray(extensions), '`fileExtensions` option requires string or array value' ); this._fileExtensions = this._fileExtensions.concat(extensions).map(function(ext) { return ext.toLowerCase(); }); }; /** * Load excluded paths. * * @param {Array} masks * @protected */ Configuration.prototype._loadExcludedFiles = function(masks) { assert(Array.isArray(masks), '`excludeFiles` option requires array value'); this._excludedFileMasks = this._excludedFileMasks.concat(masks); this._excludedFileMatchers = this._excludedFileMasks.map(function(fileMask) { return new minimatch.Minimatch(path.resolve(this._basePath, fileMask), { dot: true }); }, this); }; /** * Load paths for extract. * * @param {Array} masks * @protected */ Configuration.prototype._loadExtract = function(masks) { if (masks === true) { masks = this._defaultExtractFileMasks; } else if (masks === false) { masks = []; } assert(Array.isArray(masks), '`extract` option should be array of strings'); this._extractFileMasks = masks.slice(); this._extractFileMatchers = this._extractFileMasks.map(function(fileMask) { return new minimatch.Minimatch(path.resolve(this._basePath, fileMask), { dot: true }); }, this); }; /** * Loads custom Esprima options. * * @param {Object} esprimaOptions * @protected */ Configuration.prototype._loadEsprimaOptions = function(esprimaOptions) { assert(typeof esprimaOptions === 'object' && esprimaOptions !== null, '`esprimaOptions` should be an object'); this._esprimaOptions = esprimaOptions; }; /** * Loads additional rule. * * @param {Rule} additionalRule * @protected */ Configuration.prototype._loadAdditionalRule = function(additionalRule) { assert(typeof additionalRule === 'object', '`additionalRule` should be an object'); this.registerRule(additionalRule); }; /** * Includes plugin in the configuration environment. * * @param {function(Configuration)|*} plugin */ Configuration.prototype.usePlugin = function(plugin) { this._loadPlugin(plugin); }; /** * Apply the rules. * * @protected */ Configuration.prototype._useRules = function() { this._configuredRules = []; Object.keys(this._ruleSettings).forEach(function(optionName) { var rule = this._rules[optionName]; rule.configure(this._ruleSettings[optionName]); this._configuredRules.push(rule); }, this); }; /** * Adds rule to the collection. * * @param {Rule|Function} rule Rule instance or rule class. */ Configuration.prototype.registerRule = function(rule) { if (typeof rule === 'function') { var RuleClass = rule; rule = new RuleClass(); } var optionName = rule.getOptionName(); assert(!this._rules.hasOwnProperty(optionName), 'Rule "' + optionName + '" is already registered'); this._rules[optionName] = rule; }; /** * Returns list of registered rules. * * @returns {Rule[]} */ Configuration.prototype.getRegisteredRules = function() { var rules = this._rules; return Object.keys(rules).map(function(ruleOptionName) { return rules[ruleOptionName]; }); }; /** * Adds preset to the collection. * * @param {String} presetName * @param {Object} presetConfig */ Configuration.prototype.registerPreset = function(presetName, presetConfig) { assert(_.isPlainObject(presetConfig), 'Preset should be an object'); for (var key in presetConfig) { assert(typeof presetConfig[key] !== 'function', 'Preset should be an JSON object'); } this._presets[presetName] = presetConfig; }; /** * Returns registered presets object (key - preset name, value - preset content). * * @returns {Object} */ Configuration.prototype.getRegisteredPresets = function() { return this._presets; }; /** * Returns `true` if preset with specified name exists. * * @param {String} presetName * @return {Boolean} */ Configuration.prototype.hasPreset = function(presetName) { return this._presets.hasOwnProperty(presetName); }; /** * Returns name of the active preset. * * @return {String} */ Configuration.prototype.getPresetName = function() { return this._presetName; }; /** * Registers built-in Code Style cheking rules. */ Configuration.prototype.registerDefaultRules = function() { /* Important! These rules are linked explicitly to keep browser-version supported. */ this.registerRule(require('../rules/disallow-unused-params')); // Register jsdoc plugin this.registerRule(require('../rules/jsdoc')); /* ES6 only */ this.registerRule(require('../rules/require-parentheses-around-arrow-param')); this.registerRule(require('../rules/disallow-parentheses-around-arrow-param')); this.registerRule(require('../rules/require-numeric-literals')); this.registerRule(require('../rules/require-arrow-functions')); this.registerRule(require('../rules/disallow-arrow-functions')); this.registerRule(require('../rules/require-spread')); this.registerRule(require('../rules/require-template-strings')); this.registerRule(require('../rules/require-shorthand-arrow-functions')); this.registerRule(require('../rules/disallow-shorthand-arrow-functions')); this.registerRule(require('../rules/disallow-identical-destructuring-names')); this.registerRule(require('../rules/require-spaces-in-generator')); this.registerRule(require('../rules/disallow-spaces-in-generator')); this.registerRule(require('../rules/disallow-spaces-inside-template-string-placeholders')); this.registerRule(require('../rules/require-object-destructuring')); this.registerRule(require('../rules/require-enhanced-object-literals')); this.registerRule(require('../rules/require-array-destructuring')); this.registerRule(require('../rules/disallow-var')); this.registerRule(require('../rules/require-imports-alphabetized')); this.registerRule(require('../rules/require-space-before-destructured-values')); this.registerRule(require('../rules/disallow-array-destructuring-return')); /* ES6 only (end) */ this.registerRule(require('../rules/require-curly-braces')); this.registerRule(require('../rules/disallow-curly-braces')); this.registerRule(require('../rules/require-multiple-var-decl')); this.registerRule(require('../rules/disallow-multiple-var-decl')); this.registerRule(require('../rules/require-var-decl-first')); this.registerRule(require('../rules/disallow-empty-blocks')); this.registerRule(require('../rules/require-space-after-keywords')); this.registerRule(require('../rules/require-space-before-keywords')); this.registerRule(require('../rules/disallow-space-after-keywords')); this.registerRule(require('../rules/disallow-space-before-keywords')); this.registerRule(require('../rules/require-parentheses-around-iife')); this.registerRule(require('../rules/require-operator-before-line-break')); this.registerRule(require('../rules/disallow-operator-before-line-break')); this.registerRule(require('../rules/disallow-implicit-type-conversion')); this.registerRule(require('../rules/require-camelcase-or-uppercase-identifiers')); this.registerRule(require('../rules/disallow-keywords')); this.registerRule(require('../rules/disallow-multiple-line-breaks')); this.registerRule(require('../rules/disallow-multiple-line-strings')); this.registerRule(require('../rules/disallow-multiple-spaces')); this.registerRule(require('../rules/validate-line-breaks')); this.registerRule(require('../rules/validate-quote-marks')); this.registerRule(require('../rules/validate-indentation')); this.registerRule(require('../rules/disallow-trailing-whitespace')); this.registerRule(require('../rules/disallow-mixed-spaces-and-tabs')); this.registerRule(require('../rules/require-object-keys-on-new-line')); this.registerRule(require('../rules/disallow-object-keys-on-new-line')); this.registerRule(require('../rules/require-keywords-on-new-line')); this.registerRule(require('../rules/disallow-keywords-on-new-line')); this.registerRule(require('../rules/require-line-feed-at-file-end')); this.registerRule(require('../rules/maximum-line-length')); this.registerRule(require('../rules/require-yoda-conditions')); this.registerRule(require('../rules/disallow-yoda-conditions')); this.registerRule(require('../rules/require-spaces-inside-brackets')); this.registerRule(require('../rules/require-spaces-inside-object-brackets')); this.registerRule(require('../rules/require-spaces-inside-array-brackets')); this.registerRule(require('../rules/require-spaces-inside-parentheses')); this.registerRule(require('../rules/require-spaces-inside-parenthesized-expression')); this.registerRule(require('../rules/disallow-spaces-inside-brackets')); this.registerRule(require('../rules/disallow-spaces-inside-object-brackets')); this.registerRule(require('../rules/disallow-spaces-inside-array-brackets')); this.registerRule(require('../rules/disallow-spaces-inside-parentheses')); this.registerRule(require('../rules/disallow-spaces-inside-parenthesized-expression')); this.registerRule(require('../rules/require-blocks-on-newline')); this.registerRule(require('../rules/require-space-after-object-keys')); this.registerRule(require('../rules/require-space-before-object-values')); this.registerRule(require('../rules/disallow-space-after-object-keys')); this.registerRule(require('../rules/disallow-space-before-object-values')); this.registerRule(require('../rules/disallow-quoted-keys-in-objects')); this.registerRule(require('../rules/require-quoted-keys-in-objects')); this.registerRule(require('../rules/disallow-dangling-underscores')); this.registerRule(require('../rules/require-aligned-object-values')); this.registerRule(require('../rules/validate-aligned-function-parameters')); this.registerRule(require('../rules/disallow-padding-newlines-after-blocks')); this.registerRule(require('../rules/require-padding-newlines-after-blocks')); this.registerRule(require('../rules/disallow-padding-newlines-in-blocks')); this.registerRule(require('../rules/require-padding-newlines-in-blocks')); this.registerRule(require('../rules/require-padding-newlines-in-objects')); this.registerRule(require('../rules/disallow-padding-newlines-in-objects')); this.registerRule(require('../rules/require-newline-before-block-statements')); this.registerRule(require('../rules/disallow-newline-before-block-statements')); this.registerRule(require('../rules/require-padding-newlines-before-keywords')); this.registerRule(require('../rules/disallow-padding-newlines-before-keywords')); this.registerRule(require('../rules/disallow-padding-newlines-before-line-comments')); this.registerRule(require('../rules/require-padding-newlines-before-line-comments')); this.registerRule(require('../rules/validate-comment-position.js')); this.registerRule(require('../rules/disallow-trailing-comma')); this.registerRule(require('../rules/require-trailing-comma')); this.registerRule(require('../rules/require-dollar-before-jquery-assignment')); this.registerRule(require('../rules/disallow-comma-before-line-break')); this.registerRule(require('../rules/require-comma-before-line-break')); this.registerRule(require('../rules/disallow-space-before-block-statements.js')); this.registerRule(require('../rules/require-space-before-block-statements.js')); this.registerRule(require('../rules/disallow-space-before-postfix-unary-operators.js')); this.registerRule(require('../rules/require-space-before-postfix-unary-operators.js')); this.registerRule(require('../rules/disallow-space-after-prefix-unary-operators.js')); this.registerRule(require('../rules/require-space-after-prefix-unary-operators.js')); this.registerRule(require('../rules/disallow-space-before-binary-operators')); this.registerRule(require('../rules/require-space-before-binary-operators')); this.registerRule(require('../rules/disallow-space-after-binary-operators')); this.registerRule(require('../rules/require-space-after-binary-operators')); this.registerRule(require('../rules/require-spaces-in-conditional-expression')); this.registerRule(require('../rules/disallow-spaces-in-conditional-expression')); this.registerRule(require('../rules/require-multi-line-ternary')); this.registerRule(require('../rules/disallow-multi-line-ternary')); this.registerRule(require('../rules/disallow-nested-ternaries')); this.registerRule(require('../rules/require-spaces-in-function')); this.registerRule(require('../rules/disallow-spaces-in-function')); this.registerRule(require('../rules/require-spaces-in-function-expression')); this.registerRule(require('../rules/disallow-spaces-in-function-expression')); this.registerRule(require('../rules/require-spaces-in-anonymous-function-expression')); this.registerRule(require('../rules/disallow-spaces-in-anonymous-function-expression')); this.registerRule(require('../rules/require-spaces-in-named-function-expression')); this.registerRule(require('../rules/disallow-spaces-in-named-function-expression')); this.registerRule(require('../rules/require-spaces-in-function-declaration')); this.registerRule(require('../rules/disallow-spaces-in-function-declaration')); this.registerRule(require('../rules/require-spaces-in-call-expression')); this.registerRule(require('../rules/disallow-spaces-in-call-expression')); this.registerRule(require('../rules/validate-parameter-separator')); this.registerRule(require('../rules/require-space-between-arguments')); this.registerRule(require('../rules/disallow-space-between-arguments')); this.registerRule(require('../rules/require-capitalized-constructors')); this.registerRule(require('../rules/require-capitalized-constructors-new')); this.registerRule(require('../rules/safe-context-keyword')); this.registerRule(require('../rules/require-dot-notation')); this.registerRule(require('../rules/require-space-after-line-comment')); this.registerRule(require('../rules/disallow-space-after-line-comment')); this.registerRule(require('../rules/require-anonymous-functions')); this.registerRule(require('../rules/disallow-anonymous-functions')); this.registerRule(require('../rules/require-named-unassigned-functions')); this.registerRule(require('../rules/disallow-named-unassigned-functions')); this.registerRule(require('../rules/require-function-declarations')); this.registerRule(require('../rules/disallow-function-declarations')); this.registerRule(require('../rules/require-capitalized-comments')); this.registerRule(require('../rules/disallow-capitalized-comments')); this.registerRule(require('../rules/require-line-break-after-variable-assignment')); this.registerRule(require('../rules/require-padding-newline-after-variable-declaration')); this.registerRule(require('../rules/disallow-padding-newlines-after-use-strict')); this.registerRule(require('../rules/require-padding-newlines-after-use-strict')); this.registerRule(require('../rules/disallow-padding-newlines-before-export')); this.registerRule(require('../rules/require-padding-newlines-before-export')); this.registerRule(require('../rules/require-semicolons')); this.registerRule(require('../rules/disallow-semicolons')); this.registerRule(require('../rules/require-spaces-in-for-statement')); this.registerRule(require('../rules/disallow-spaces-in-for-statement')); this.registerRule(require('../rules/disallow-node-types')); this.registerRule(require('../rules/disallow-keywords-in-comments')); this.registerRule(require('../rules/disallow-identifier-names')); this.registerRule(require('../rules/maximum-number-of-lines')); this.registerRule(require('../rules/validate-newline-after-array-elements')); this.registerRule(require('../rules/disallow-not-operators-in-conditionals')); this.registerRule(require('../rules/require-matching-function-name')); this.registerRule(require('../rules/disallow-space-before-semicolon')); this.registerRule(require('../rules/disallow-space-before-comma')); this.registerRule(require('../rules/disallow-space-after-comma')); this.registerRule(require('../rules/require-space-before-comma')); this.registerRule(require('../rules/require-space-after-comma')); this.registerRule(require('../rules/validate-order-in-object-keys')); this.registerRule(require('../rules/disallow-tabs')); this.registerRule(require('../rules/require-aligned-multiline-params')); this.registerRule(require('../rules/require-early-return')); this.registerRule(require('../rules/require-newline-before-single-statements-in-if')); }; /** * Registers built-in Code Style cheking presets. */ Configuration.prototype.registerDefaultPresets = function() { // https://github.com/airbnb/javascript this.registerPreset('airbnb', require('../../presets/airbnb.json')); // http://javascript.crockford.com/code.html this.registerPreset('crockford', require('../../presets/crockford.json')); // https://google-styleguide.googlecode.com/svn/trunk/javascriptguide.xml this.registerPreset('google', require('../../presets/google.json')); // http://gruntjs.com/contributing#syntax this.registerPreset('grunt', require('../../presets/grunt.json')); // https://github.com/rwaldron/idiomatic.js#idiomatic-style-manifesto this.registerPreset('idiomatic', require('../../presets/idiomatic.json')); // https://contribute.jquery.org/style-guide/js/ this.registerPreset('jquery', require('../../presets/jquery.json')); // https://github.com/mrdoob/three.js/wiki/Mr.doob's-Code-Style%E2%84%A2 this.registerPreset('mdcs', require('../../presets/mdcs.json')); // https://github.com/felixge/node-style-guide#nodejs-style-guide this.registerPreset('node-style-guide', require('../../presets/node-style-guide.json')); // https://www.mediawiki.org/wiki/Manual:Coding_conventions/JavaScript this.registerPreset('wikimedia', require('jscs-preset-wikimedia')); // https://make.wordpress.org/core/handbook/coding-standards/javascript/ this.registerPreset('wordpress', require('../../presets/wordpress.json')); // https://github.com/yandex/codestyle/blob/master/javascript.md this.registerPreset('yandex', require('../../presets/yandex.json')); }; module.exports = Configuration; function copyConfiguration(source, dest) { Object.keys(source).forEach(function(key) { dest[key] = source[key]; }); if (source.configPath) { dest.configPath = source.configPath; } } },{"../../presets/airbnb.json":969,"../../presets/crockford.json":970,"../../presets/google.json":971,"../../presets/grunt.json":972,"../../presets/idiomatic.json":973,"../../presets/jquery.json":974,"../../presets/mdcs.json":975,"../../presets/node-style-guide.json":976,"../../presets/wordpress.json":977,"../../presets/yandex.json":978,"../rules/disallow-anonymous-functions":4,"../rules/disallow-array-destructuring-return":5,"../rules/disallow-arrow-functions":6,"../rules/disallow-capitalized-comments":7,"../rules/disallow-comma-before-line-break":8,"../rules/disallow-curly-braces":9,"../rules/disallow-dangling-underscores":10,"../rules/disallow-empty-blocks":11,"../rules/disallow-function-declarations":12,"../rules/disallow-identical-destructuring-names":13,"../rules/disallow-identifier-names":14,"../rules/disallow-implicit-type-conversion":15,"../rules/disallow-keywords":18,"../rules/disallow-keywords-in-comments":16,"../rules/disallow-keywords-on-new-line":17,"../rules/disallow-mixed-spaces-and-tabs":19,"../rules/disallow-multi-line-ternary":20,"../rules/disallow-multiple-line-breaks":21,"../rules/disallow-multiple-line-strings":22,"../rules/disallow-multiple-spaces":23,"../rules/disallow-multiple-var-decl":24,"../rules/disallow-named-unassigned-functions":25,"../rules/disallow-nested-ternaries":26,"../rules/disallow-newline-before-block-statements":27,"../rules/disallow-node-types":28,"../rules/disallow-not-operators-in-conditionals":29,"../rules/disallow-object-keys-on-new-line":30,"../rules/disallow-operator-before-line-break":31,"../rules/disallow-padding-newlines-after-blocks":32,"../rules/disallow-padding-newlines-after-use-strict":33,"../rules/disallow-padding-newlines-before-export":34,"../rules/disallow-padding-newlines-before-keywords":35,"../rules/disallow-padding-newlines-before-line-comments":36,"../rules/disallow-padding-newlines-in-blocks":37,"../rules/disallow-padding-newlines-in-objects":38,"../rules/disallow-parentheses-around-arrow-param":39,"../rules/disallow-quoted-keys-in-objects":40,"../rules/disallow-semicolons":41,"../rules/disallow-shorthand-arrow-functions":42,"../rules/disallow-space-after-binary-operators":43,"../rules/disallow-space-after-comma":44,"../rules/disallow-space-after-keywords":45,"../rules/disallow-space-after-line-comment":46,"../rules/disallow-space-after-object-keys":47,"../rules/disallow-space-after-prefix-unary-operators.js":48,"../rules/disallow-space-before-binary-operators":49,"../rules/disallow-space-before-block-statements.js":50,"../rules/disallow-space-before-comma":51,"../rules/disallow-space-before-keywords":52,"../rules/disallow-space-before-object-values":53,"../rules/disallow-space-before-postfix-unary-operators.js":54,"../rules/disallow-space-before-semicolon":55,"../rules/disallow-space-between-arguments":56,"../rules/disallow-spaces-in-anonymous-function-expression":57,"../rules/disallow-spaces-in-call-expression":58,"../rules/disallow-spaces-in-conditional-expression":59,"../rules/disallow-spaces-in-for-statement":60,"../rules/disallow-spaces-in-function":63,"../rules/disallow-spaces-in-function-declaration":61,"../rules/disallow-spaces-in-function-expression":62,"../rules/disallow-spaces-in-generator":64,"../rules/disallow-spaces-in-named-function-expression":65,"../rules/disallow-spaces-inside-array-brackets":66,"../rules/disallow-spaces-inside-brackets":67,"../rules/disallow-spaces-inside-object-brackets":68,"../rules/disallow-spaces-inside-parentheses":69,"../rules/disallow-spaces-inside-parenthesized-expression":70,"../rules/disallow-spaces-inside-template-string-placeholders":71,"../rules/disallow-tabs":72,"../rules/disallow-trailing-comma":73,"../rules/disallow-trailing-whitespace":74,"../rules/disallow-unused-params":75,"../rules/disallow-var":76,"../rules/disallow-yoda-conditions":77,"../rules/jsdoc":78,"../rules/maximum-line-length":79,"../rules/maximum-number-of-lines":80,"../rules/require-aligned-multiline-params":81,"../rules/require-aligned-object-values":82,"../rules/require-anonymous-functions":83,"../rules/require-array-destructuring":84,"../rules/require-arrow-functions":85,"../rules/require-blocks-on-newline":86,"../rules/require-camelcase-or-uppercase-identifiers":87,"../rules/require-capitalized-comments":88,"../rules/require-capitalized-constructors":90,"../rules/require-capitalized-constructors-new":89,"../rules/require-comma-before-line-break":91,"../rules/require-curly-braces":92,"../rules/require-dollar-before-jquery-assignment":93,"../rules/require-dot-notation":94,"../rules/require-early-return":95,"../rules/require-enhanced-object-literals":96,"../rules/require-function-declarations":97,"../rules/require-imports-alphabetized":98,"../rules/require-keywords-on-new-line":99,"../rules/require-line-break-after-variable-assignment":100,"../rules/require-line-feed-at-file-end":101,"../rules/require-matching-function-name":102,"../rules/require-multi-line-ternary":103,"../rules/require-multiple-var-decl":104,"../rules/require-named-unassigned-functions":105,"../rules/require-newline-before-block-statements":106,"../rules/require-newline-before-single-statements-in-if":107,"../rules/require-numeric-literals":108,"../rules/require-object-destructuring":109,"../rules/require-object-keys-on-new-line":110,"../rules/require-operator-before-line-break":111,"../rules/require-padding-newline-after-variable-declaration":112,"../rules/require-padding-newlines-after-blocks":113,"../rules/require-padding-newlines-after-use-strict":114,"../rules/require-padding-newlines-before-export":115,"../rules/require-padding-newlines-before-keywords":116,"../rules/require-padding-newlines-before-line-comments":117,"../rules/require-padding-newlines-in-blocks":118,"../rules/require-padding-newlines-in-objects":119,"../rules/require-parentheses-around-arrow-param":120,"../rules/require-parentheses-around-iife":121,"../rules/require-quoted-keys-in-objects":122,"../rules/require-semicolons":123,"../rules/require-shorthand-arrow-functions":124,"../rules/require-space-after-binary-operators":125,"../rules/require-space-after-comma":126,"../rules/require-space-after-keywords":127,"../rules/require-space-after-line-comment":128,"../rules/require-space-after-object-keys":129,"../rules/require-space-after-prefix-unary-operators.js":130,"../rules/require-space-before-binary-operators":131,"../rules/require-space-before-block-statements.js":132,"../rules/require-space-before-comma":133,"../rules/require-space-before-destructured-values":134,"../rules/require-space-before-keywords":135,"../rules/require-space-before-object-values":136,"../rules/require-space-before-postfix-unary-operators.js":137,"../rules/require-space-between-arguments":138,"../rules/require-spaces-in-anonymous-function-expression":139,"../rules/require-spaces-in-call-expression":140,"../rules/require-spaces-in-conditional-expression":141,"../rules/require-spaces-in-for-statement":142,"../rules/require-spaces-in-function":145,"../rules/require-spaces-in-function-declaration":143,"../rules/require-spaces-in-function-expression":144,"../rules/require-spaces-in-generator":146,"../rules/require-spaces-in-named-function-expression":147,"../rules/require-spaces-inside-array-brackets":148,"../rules/require-spaces-inside-brackets":149,"../rules/require-spaces-inside-object-brackets":150,"../rules/require-spaces-inside-parentheses":151,"../rules/require-spaces-inside-parenthesized-expression":152,"../rules/require-spread":153,"../rules/require-template-strings":154,"../rules/require-trailing-comma":155,"../rules/require-var-decl-first":156,"../rules/require-yoda-conditions":157,"../rules/safe-context-keyword":158,"../rules/validate-aligned-function-parameters":159,"../rules/validate-comment-position.js":160,"../rules/validate-indentation":161,"../rules/validate-line-breaks":162,"../rules/validate-newline-after-array-elements":163,"../rules/validate-order-in-object-keys":164,"../rules/validate-parameter-separator":165,"../rules/validate-quote-marks":166,"assert":176,"jscs-preset-wikimedia":749,"lodash":777,"minimatch":881,"path":886}],2:[function(require,module,exports){ var assert = require('assert'); var chalk = require('chalk'); var TokenAssert = require('./token-assert'); /** * Set of errors for specified file. * * @name Errors * @param {JsFile} file * @param {Boolean} verbose */ var Errors = function(file, verbose) { this._errorList = []; this._file = file; this._currentRule = ''; this._verbose = verbose || false; /** * @type {TokenAssert} * @public */ this.assert = new TokenAssert(file); this.assert.on('error', this._addError.bind(this)); }; Errors.prototype = { /** * Adds style error to the list * * @param {String} message * @param {Number|Object} line * @param {Number} [column] optional if line is an object */ add: function(message, line, column) { if (typeof line === 'object') { column = line.column; line = line.line; } var errorInfo = { message: message, line: line, column: column }; this._validateInput(errorInfo); this._addError(errorInfo); }, /** * Adds style error to the list * * @param {Object} errorInfo */ cast: function(errorInfo) { var additional = errorInfo.additional; assert(typeof additional !== undefined, '`additional` argument should not be empty'); this._addError(errorInfo); }, _validateInput: function(errorInfo) { var line = errorInfo.line; var column = errorInfo.column; // line and column numbers should be explicit assert(typeof line === 'number' && line > 0, 'Unable to add an error, `line` should be a number greater than 0 but ' + line + ' given'); assert(typeof column === 'number' && column >= 0, 'Unable to add an error, `column` should be a positive number but ' + column + ' given'); }, /** * Adds error to error list. * * @param {Object} errorInfo * @private */ _addError: function(errorInfo) { if (!this._file.isEnabledRule(this._currentRule, errorInfo.line)) { return; } this._validateInput(errorInfo); this._errorList.push({ filename: this._file.getFilename(), rule: this._currentRule, message: this._prepareMessage(errorInfo), line: errorInfo.line, column: errorInfo.column, additional: errorInfo.additional, fixed: errorInfo.fixed }); }, /** * Prepare error message. * * @param {Object} errorInfo * @private */ _prepareMessage: function(errorInfo) { if (this._verbose && this._currentRule) { return this._currentRule + ': ' + errorInfo.message; } return errorInfo.message; }, /** * Returns style error list. * * @returns {Object[]} */ getErrorList: function() { return this._errorList; }, /** * Returns filename of file this error list is for. * * @returns {String} */ getFilename: function() { return this._file.getFilename(); }, /** * Returns true if no errors are added. * * @returns {Boolean} */ isEmpty: function() { return this._errorList.length === 0; }, /** * Returns amount of errors added by the rules. * * @returns {Number} */ getErrorCount: function() { return this._errorList.length; }, /** * Strips error list to the specified length. * * @param {Number} length */ stripErrorList: function(length) { this._errorList.splice(length); }, /** * Filters out errors based on the supplied filter function * * @param {Function} filter */ filter: function(filter) { this._errorList = this._errorList.filter(filter); }, /** * Formats error for further output. * * @param {Object} error * @param {Boolean} [colorize = false] * @returns {String} */ explainError: function(error, colorize) { var lineNumber = error.line - 1; var lines = this._file.getLines(); var result = [ renderLine(lineNumber, lines[lineNumber], colorize), renderPointer(error.column, colorize) ]; var i = lineNumber - 1; var linesAround = 2; while (i >= 0 && i >= (lineNumber - linesAround)) { result.unshift(renderLine(i, lines[i], colorize)); i--; } i = lineNumber + 1; while (i < lines.length && i <= (lineNumber + linesAround)) { result.push(renderLine(i, lines[i], colorize)); i++; } result.unshift(formatErrorMessage(error.message, this.getFilename(), colorize)); return result.join('\n'); }, /** * Sets the current rule so that errors are aware * of which rule triggered them. * * @param {String} rule */ setCurrentRule: function(rule) { this._currentRule = rule; } }; /** * Formats