'use strict'

const standard = require('standard')
const format = require('util').format
const assign = require('object-assign')
const loaderUtils = require('loader-utils')

module.exports = function standardLoader (text) {
  const self = this
  const callback = this.async()

  const config = assign(
    this.options.standard || {},
    loaderUtils.parseQuery(this.query)
  )

  this.cacheable()

  standard.lintText(text, config, function (err, result) {
    if (err) return callback(err, text)
    if (result.errorCount === 0) return callback(err, text)

    const warnings = result.results.reduce(function (items, result) {
      return items.concat(result.messages.map(function (message) {
        return format(
          '%s:%d:%d: %s',
          result.filePath, message.line || 0, message.column || 0, message.message
        )
      }))
    }, [])

    self.emitWarning(warnings.join('\n'))
    callback(err, text)
  })
}

'use strict'

var standard = require('standard')
var format = require('util').format
var assign = require('object-assign')
var loaderUtils = require('loader-utils')

module.exports = function standardLoader (text) {
  var self = this
  var callback = this.async()

  var config = assign(
    this.options.standard || {},
    loaderUtils.parseQuery(this.query)
  )

  this.cacheable()

  standard.lintText(text, config, function (err, result) {
    if (err) return callback(err, text)
    if (result.errorCount === 0) return callback(err, text)

    var warnings = result.results.reduce(function (items, result) {
      return items.concat(result.messages.map(function (message) {
        return format(
          '%s:%d:%d: %s',
          result.filePath, message.line || 0, message.column || 0, message.message
        )
      }))
    }, [])

    self.emitWarning(warnings.join('\n'))
    callback(err, text)
  })
}

Remove const in strict-mode for 0.10.x.