<commit_before>/**
 * lib/lint.js - gulp-jslint
 * Copyright (C) 2014-2016 <NAME>.
 */

'use strict';

const LintStream = require('jslint').LintStream,
      map = require('map-stream'),
      path = require('path'),
      rc = require('rc');

/**
 * The outer linting function that creates an output
 * object.
 * 
 * @param options a JSON object containing defined options
 */
module.exports = function (options) {
    // fallback to empty object
    options = options || {};

    // extend .jslintrc; give options
    // the priority for directives
    options = rc('jslint', options);

    // force boolean and remove from options
    const errorsOnly = options.hasOwnProperty('errorsOnly') && options.errorsOnly === true;
    delete options.errorsOnly;

    // use 'global' for consistency prefer 'predef' because of JSLint
    options.predef = options.predef || options.global || {};
    
    // freeze to user's prefered edition or use latest
    options.edition = options.edition || 'latest';

    // create a new lint stream 
    const lintStream = new LintStream(options);

    // map the incoming vinyl object to the object
    // expected by the lint stream 
    const stream = map((data, next) => {
        const source = data.source;
        
        // only continue with file inputs
        if (source.isNull()) return next(null, source);
        if (source.isStream()) return next(new gutil.PluginError('gulp-jslint', 'Not sure how to handle stream as input file.'));
        next(null, {
            file: data,
            body: source.contents.toString('utf8')
        });
    });
    
    // begin linting
    stream.pipe(lintStream)

        // map the lint stream results object back to the
        // vinyl object expected by the reporter and rest
        // of the gulp stream
        .pipe(map((data, next) => {
            const source = data.file.source;
            if (source.isNull()) return next(null, source);

            // map over the properties required by a lint reporter
            source.jslint = {};
            source.jslint.success = data.linted.ok;
            source.jslint.errors = data.linted.errors;
            source.jslint.warnings = data.linted.warnings;<commit_msg>simplify setting of jslint results and add filename to results<commit_after>/**
 * lib/lint.js - gulp-jslint
 * Copyright (C) 2014-2016 <NAME>.
 */

'use strict';

const LintStream = require('jslint').LintStream,
      map = require('map-stream'),
      path = require('path'),
      rc = require('rc');

/**
 * The outer linting function that creates an output
 * object.
 * 
 * @param options a JSON object containing defined options
 */
module.exports = function (options) {
    // fallback to empty object
    options = options || {};

    // extend .jslintrc; give options
    // the priority for directives
    options = rc('jslint', options);

    // force boolean and remove from options
    const errorsOnly = options.hasOwnProperty('errorsOnly') && options.errorsOnly === true;
    delete options.errorsOnly;

    // use 'global' for consistency prefer 'predef' because of JSLint
    options.predef = options.predef || options.global || {};
    
    // freeze to user's prefered edition or use latest
    options.edition = options.edition || 'latest';

    // create a new lint stream 
    const lintStream = new LintStream(options);

    // map the incoming vinyl object to the object
    // expected by the lint stream 
    const stream = map((data, next) => {
        const source = data.source;
        
        // only continue with file inputs
        if (source.isNull()) return next(null, source);
        if (source.isStream()) return next(new gutil.PluginError('gulp-jslint', 'Not sure how to handle stream as input file.'));
        next(null, {
            file: data,
            body: source.contents.toString('utf8')
        });
    });

    // begin linting
    stream.pipe(lintStream)

        // map the lint stream results object back to the
        // vinyl object expected by the reporter and rest
        // of the gulp stream
        .pipe(map((data, next) => {
            const source = data.file.source;
            if (source.isNull()) return next(null, source);

            // map over the properties required by a lint reporter
            source.jslint = {
                filename: source.path,
                success: data.linted.ok,
                errors: data.linted.errors,
                warnings: data.linted.warnings
            };
{'fraction_non_alphanumeric': 0.11325782811459027, 'fraction_numerical': 0.003997335109926716, 'mean_word_length': 2.2948061448427213, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 9, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '285492', 'n_tokens_mistral': 1264, 'n_tokens_neox': 1217, 'n_words': 408}