<commit_before>###
CoffeeLint

Copyright (c) 2011 <NAME>.
CoffeeLint is freely distributable under the MIT license.
###


resolve = require('resolve').sync
path = require("path")
fs   = require("fs")
os   = require("os")
glob = require("glob")
optimist = require("optimist")
ignore = require('ignore')
stripComments = require('strip-json-comments')
thisdir = path.dirname(fs.realpathSync(__filename))
coffeelint = require(path.join(thisdir, "coffeelint"))
configfinder = require(path.join(thisdir, "configfinder"))
ruleLoader = require(path.join(thisdir, 'ruleLoader'))
Cache = require(path.join(thisdir, "cache"))
CoffeeScript = require 'coffee-script'
CoffeeScript.register()

log = ->
    # coffeelint: disable=no_debugger
    console.log(arguments...)
    # coffeelint: enable=no_debugger

logConfig = (config) ->
    filter = (k, v) -> v unless k in ['message', 'description', 'name']

    log(JSON.stringify(config, filter, 4))

# Return the contents of the given file synchronously.
read = (path) ->
    realPath = fs.realpathSync(path)
    return fs.readFileSync(realPath).toString()

# Return a list of CoffeeScript's in the given paths.
findCoffeeScripts = (paths) ->
    files = []
    for p in paths
        if fs.statSync(p).isDirectory()
            # The glob library only uses forward slashes.
            files = files.concat(glob.sync("#{p}/**/*.coffee"))
        else
            files.push(p)
    return files

# Return an error report from linting the given paths.
lintFiles = (files, config) ->


    errorReport = new coffeelint.getErrorReport()
    for file in files
        source = read(file)
        literate = CoffeeScript.helpers.isLiterate file

        fileConfig = if config then config else getFallbackConfig(file)

        errorReport.lint(file, source, fileConfig, literate)
    return errorReport

# Return an error report from linting the given coffeescript source.
lintSource = (source, config, literate = false) ->
    errorReport = new coffeelint.getErrorReport()
    config or= getFallbackConfig()

    errorReport.lint("stdin", source, config, literate)
    return errorReport

# Load a config file given a path/filename
readConfigFile = (path) ->
    JSON.parse(stripComments(read(path)))

loadConfig = (options) ->
    config = null
    unless options.argv.noconfig
        if options.argv.f
            config = readConfigFile(options.argv.f)

            # If -f was specifying a package.json, extract the config<commit_msg>[trimconfig] Make an effort to maintain the original file's indentation<commit_after>###
CoffeeLint

Copyright (c) 2011 <NAME>.
CoffeeLint is freely distributable under the MIT license.
###


resolve = require('resolve').sync
path = require("path")
fs   = require("fs")
os   = require("os")
glob = require("glob")
optimist = require("optimist")
ignore = require('ignore')
stripComments = require('strip-json-comments')
thisdir = path.dirname(fs.realpathSync(__filename))
coffeelint = require(path.join(thisdir, "coffeelint"))
configfinder = require(path.join(thisdir, "configfinder"))
ruleLoader = require(path.join(thisdir, 'ruleLoader'))
Cache = require(path.join(thisdir, "cache"))
CoffeeScript = require 'coffee-script'
CoffeeScript.register()

log = ->
    # coffeelint: disable=no_debugger
    console.log(arguments...)
    # coffeelint: enable=no_debugger

jsonIndentation = 2
logConfig = (config) ->
    filter = (k, v) -> v unless k in ['message', 'description', 'name']
    log(JSON.stringify(config, filter, jsonIndentation))

# Return the contents of the given file synchronously.
read = (path) ->
    realPath = fs.realpathSync(path)
    return fs.readFileSync(realPath).toString()

# Return a list of CoffeeScript's in the given paths.
findCoffeeScripts = (paths) ->
    files = []
    for p in paths
        if fs.statSync(p).isDirectory()
            # The glob library only uses forward slashes.
            files = files.concat(glob.sync("#{p}/**/*.coffee"))
        else
            files.push(p)
    return files

# Return an error report from linting the given paths.
lintFiles = (files, config) ->


    errorReport = new coffeelint.getErrorReport()
    for file in files
        source = read(file)
        literate = CoffeeScript.helpers.isLiterate file

        fileConfig = if config then config else getFallbackConfig(file)

        errorReport.lint(file, source, fileConfig, literate)
    return errorReport

# Return an error report from linting the given coffeescript source.
lintSource = (source, config, literate = false) ->
    errorReport = new coffeelint.getErrorReport()
    config or= getFallbackConfig()

    errorReport.lint("stdin", source, config, literate)
    return errorReport

# Load a config file given a path/filename
readConfigFile = (path) ->
    text = read(path)
    try
        jsonIndentation = text.split('\n')[1].match(/^\s+/)[0].length
    JSON.parse(stripComments(text))

loadConfig = (options) ->
    config = null
    unless options.argv.noconfig
        if options.argv.f
            config = readConfigFile(options.argv.f)

            # If -f was specifying a package.json, extract the config
{'fraction_non_alphanumeric': 0.11921951219512195, 'fraction_numerical': 0.0023414634146341463, 'mean_word_length': 3.5931899641577063, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 23, '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': '624086', 'n_tokens_mistral': 1568, 'n_tokens_neox': 1508, 'n_words': 429}