How to use the standard.lintTextSync 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 elastic / elasticsearch-js / scripts / generate-docs-examples.js View on Github external
asciidoc += '// Use `node scripts/generate-docs-examples.js` to generate the docs examples\n\n'
  var code = 'async function run (client) {\n// START\n'

  for (var i = 0; i < source.length; i++) {
    const { api, query, params, body } = source[i]
    const apiArguments = Object.assign({}, params, query, body ? { body } : body)
    var serializedApiArguments = Object.keys(apiArguments).length > 0
      ? JSON.stringify(apiArguments, null, 2)
      : ''
    code += `const response${getResponsePostfix(i)} = await client.${api.replace(/_([a-z])/g, g => g[1].toUpperCase())}(${serializedApiArguments})
console.log(response${getResponsePostfix(i)})
\n`
  }

  code += '// END\n}'
  const { results } = standard.lintTextSync(code, { fix: true })
  code = results[0].output
  code = code.slice(code.indexOf('// START\n') + 9, code.indexOf('\n\n// END'))

  asciidoc += `[source, js]
----
${dedent(code)}
----

`
  return asciidoc

  function getResponsePostfix (i) {
    if (source.length === 1) return ''
    return String(i)
  }
}
github wanseob / truffle-plugin-modularizer / src / modularizer.js View on Github external
// Backward compatibility
          process.emitWarning('It is recommended to use a Web3 instance instead of Web3Provider')
          contract.setProvider(web3)
        } else {
          throw Error('You should provide a valid web3 instance')
        }
      }
      return contract
    }
    
    module.exports = {
      ${Object.keys(artifacts).map(toFactoryScript).join(',')}
    }
    `
    // It makes the script prettier with standardJS style
    const lintResult = standard.lintTextSync(module, { fix: true })
    const scriptToWrite = lintResult.results[0].output

    // Check does it already exist, if then check the diff and decide to update or not
    try {
      const legacy = fs.readFileSync(outputPath, 'utf8')
      if (legacy === scriptToWrite) {
        console.log('truffle-plugin-modularizer: No updates')
        resolve()
        return
      }
    } catch (e) {}

    // Make directory if it does not exist
    fs.mkdir(path.dirname(outputPath), { recursive: true }, (err) => {
      if (err) reject(err)
      else {
github mafintosh / hyperdb / test / helpers / fuzzing.js View on Github external
var run = require('./helpers/run')
    var put = require('./helpers/put')
    var create = require('./helpers/create')
    var validate = require('./helpers/fuzzing').validate

    tape('autogenerated failing fuzz test', function (t) {
      var writesPerReplication = ${JSON.stringify(writeArrays)}.map(b => new Map(b))

      create.many(${dbCount}, function (err, dbs, replicateByIndex) {
        t.error(err)
        run(${writeOps.map(op => op.toString())})
      })
    })`, { singleQuote: true, semi: false })

  var standardized = standard.lintTextSync(source, { fix: true })
  console.log(standardized.results[0].output)
  console.log('\n')
}
github Aceheliflyer / AceBot / src / commands / utility / lint.js View on Github external
async run (message, args) {
    var hrStart = await process.hrtime(this.hrStart)
    var lintResult = await standard.lintTextSync(`${args.code}\n`)
    var lintLatency = await process.hrtime(hrStart)

    var messages = lintResult.results[0].messages.map(m => stripIndents`
      **${m.ruleId ? m.ruleId : 'Error'} - (${m.line}:${m.column})**
      ❯ ${m.message}
    `).join('\n')

    message.embed({
      author: { name: this.client.user.tag, icon_url: this.client.user.displayAvatarURL() },
      footer: { text: message.author.tag, icon_url: message.author.displayAvatarURL() },
      timestamp: new Date(),
      title: `*Linted in ${lintLatency[0] > 0 ? `${lintLatency[0]}s ` : ''}${lintLatency[1] / 1000000}ms.*`,
      description: messages ? messages.slice(0, 2000) : '✅ Lint Success!',
      color: this.client.getClientColor(message)
    })
  }
github davidjamesstone / hyperviews / index.js View on Github external
break
          case 'cjs':
            result = `module.exports = ${value}`
            break
          case 'browser':
            result = `window.${name} = ${value}`
            break
          default:
            result = `${mode ? `var ${mode} =` : ''} ${value}`
        }
      } else {
        result = value
      }
    }

    const lintResult = standard.lintTextSync(result, { fix: true })

    return lintResult.results[0].output
  } catch (err) {
    throw new Error(`Error ${err.message}\n${result}\nraw:\n${js}`)
  }
}
github shimohq / generator2async-codemod / lib / generator2async.js View on Github external
if (argument && argument.type === 'AwaitExpression') {
        const stmt = j.returnStatement(argument.argument)
        stmt.comments = comments
        j(path).replaceWith(stmt)
      }
      if (argument && argument.type === 'ConditionalExpression') {
        const { test, consequent, alternate } = argument
        const stmt = j.returnStatement(j.conditionalExpression(test,
          consequent.type === 'AwaitExpression' ? consequent.argument : consequent,
          alternate.type === 'AwaitExpression' ? alternate.argument : alternate))
        j(path).replaceWith(stmt)
      }
    })

  const source = root.toSource()
  const { results: [{ output }] } = standard.lintTextSync(source, { fix: true })
  return output
}

standard

JavaScript Standard Style

MIT
Latest version published 6 days ago

Package Health Score

79 / 100
Full package analysis