How to use the standard.lintText function in standard

To help you get started, we’ve selected a few standard examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github maxogden / standard-format / test / testFile.js View on Github external
fs.readFile(filePath, { encoding: 'utf8' }, function (err, data) {
      t.error(err, 'read ' + basename + ' file without error ')

      var formatted

      try {
        formatted = fmt(data)
      } catch (e) {
        t.error(e, 'format ' + basename + ' without error')
      }

      standard.lintText(formatted, function (err, result) {
        t.error(err, 'linting ' + basename + ' should be error free')
        t.equal(result.errorCount, 0, basename + ' error free after formatting')
        t.equal(result.warningCount, 0, basename + ' warning free after formatting')
        if (result.errorCount || result.warningCount !== 0) {
          // If there is an issue, print the details
          console.log(inspect(result, { depth: depth || null }))
        }
        t.end()
      })
    })
  }
github vigour-io / brisky / test / watch.js View on Github external
raw[l] = raw[l].slice(0, -1)
    }
    raw.push('},')
    // raw.push(',')
  } else {
    raw.push(key + ': ' + result + ',')
  }
}
parseRaw(result.subs)
raw[raw.length - 1] = raw[raw.length - 1].slice(0, -1)
// raw.unshift(`const { findParent } = require('./framework')\n`)
// fs.writeFileSync(__dirname + '/jsx.transpiled.real.js', raw.join('\n'))
// will make this super nice
const str = result.init + '\n' + raw.join('\n')

standard.lintText(str, { fix: true }, (err, data) => {
  if (err) console.log('ERR!', err)
  // console.log(data.results[0])
  fs.writeFileSync(__dirname + '/jsx.transpiled.real.js', data.results[0].output)  //eslint-disable-line
})
github probot / linter / lib / index.js View on Github external
return Promise.all(compare.data.files.map(async file => {
      if (!whiteList.includes(file.filename)) {
        const content = await context.github.repos.getContent(context.repo({
          path: file.filename,
          ref: branch
        }));
        console.log(content);
        const text = Buffer.from(content.data.content, 'base64').toString();
        Object.assign(linterItems, {cwd: '', fix: true, filename: file.filename});
        console.log(linterItems);

        standard.lintText(text, linterItems, (err, results) => {
          if (err) {
            console.log('err: ', err);
          }
          console.log('res', results);
          return Promise.all(results.results.map(result => {
            console.log(result);
            if (result.output) {
              console.log('output', result.output);
              // Checks that we have a fixed version and the file isn't part of the whiteList
              context.github.repos.updateFile(context.repo({
                path: file.filename,
                message: `Fix lint errors for ${file.filename}`,
                content: Buffer.from(result.output).toString('base64'),
                sha: content.data.sha,
                branch
              }));
github ngnjs / NGN / test / syntax-checker.js View on Github external
result.results.forEach(function (result) {
      result.messages.forEach(function (message) {
        console.log(
          '  %s:%d:%d: %s%s',
          result.filePath, message.line || 0, message.column || 0, message.message,
          Args.value('verbose') ? ' (' + message.ruleId + ')' : ''
        )
      })
    })

    process.exitCode = result.errorCount ? 1 : 0
  }
}

if (scanFile) {
  standard.lintText(fs.readFileSync(scanpath).toString(), opts, output)
} else {
  standard.lintFiles(scanpath, opts, output)
}
github emgeee / gulp-standard / index.js View on Github external
function processFile (file, enc, cb) {
    if (file.isNull()) {
      return cb(null, file)
    }

    if (file.isStream()) {
      return cb(new PluginError(PLUGIN_NAME, 'Streams are not supported!'))
    }

    standard.lintText(String(file.contents), Object.assign({
      filename: file.path
    }, opts), function (err, data) {
      if (err) {
        return cb(err)
      }
      file.standard = data
      if (data.results[0] && data.results[0].output) {
        file.contents = Buffer.from(data.results[0].output)
        data.fixed = true
      }
      cb(null, file)
    })
  }
github dtinth / prettier-standard-formatter / index.js View on Github external
exports.format = source => new Promise((resolve, reject) => {
  const pretty = prettier.format(source, {
    printWidth: 80,
    tabWidth: 2,
    parser: 'babylon',
    singleQuote: true,
    trailingComma: 'none',
    bracketSpacing: true
  })
  standard.lintText(pretty, { fix: true }, (err, result) => {
    if (err) {
      return reject(err)
    }
    const output = result.results[0].output
    if (typeof output !== 'string') {
      return reject(new Error('Expected a string back from standard'))
    }
    resolve(output)
  })
})
github zeke / standard-markdown / lib / linter.js View on Github external
return new Promise((resolve, reject) => {
      standard.lintText(ignoredBlock, standardOptions, (err, results) => {
        if (err) return reject(err)
        results.originalLine = block.line
        results.originalText = block
        return resolve(results)
      })
    })
  })).then((results) => {

standard

JavaScript Standard Style

MIT
Latest version published 2 months ago

Package Health Score

73 / 100
Full package analysis