Example #1
0
} = () => {
  return {
    visitor: {
      Program (_, state) {
        const { file: { code } } = state
        const report = cli.executeOnText(code)
        if (report.errorCount > 0) {
          for (const result of report.results) {
            for (const msg of result.messages) {
              const err = codeFrameError({
                start: {
                  line: msg.line,
                  column: msg.column
                },
                end: {
                  line: msg.endLine,
                  column: msg.endColumn
                }
              }, msg.message)
              // tslint:disable-next-line
              console.warn('\n' + `ESLint(${msg.ruleId}) 错误:` + err.message.replace('Declare only one React component per file', '一个文件只能定义一个 Taro 类或 Taro 函数式组件') + '\n')
            }
          }
        }
      }
    }
  }
}
Example #2
0
} = () => {
  return {
    visitor: {
      Program (_, state) {
        const { file: { code } } = state
        const report = cli.executeOnText(code)
        if (report.errorCount > 0) {
          for (const result of report.results) {
            for (const msg of result.messages) {
              const err = codeFrameError({
                start: {
                  line: msg.line,
                  column: msg.column
                },
                end: {
                  line: msg.endLine,
                  column: msg.endColumn
                }
              }, msg.message)
              // tslint:disable-next-line
              console.warn('\n' + `ESLint(${msg.ruleId}) 错误:` + err.message + '\n')
            }
          }
        }
      }
    }
  }
}
Example #3
0
export default function () {
  const eslintCli = new CLIEngine({
    cwd: process.cwd(),
    useEslintrc: false,
    configFile: ESLINT_CONFIG_PATH
  })

  const sourceFiles = path.join(process.cwd(), projectConf.sourceRoot, '**/*.{js,ts,jsx,tsx}')
  const report = eslintCli.executeOnFiles([sourceFiles])
  const formatter = eslintCli.getFormatter()

  return {
    desc: '检查 ESLint (以下为 ESLint 的输出)',
    raw: formatter(report.results)
  }
}
Example #4
0
export function doValidation(document: TextDocument, engine: CLIEngine): Diagnostic[] {
  const rawText = document.getText();
  // skip checking on empty template
  if (rawText.replace(/\s/g, '') === '') {
    return [];
  }
  const text = rawText.replace(/ {10}/, '<template>') + '</template>';
  const report = engine.executeOnText(text, document.uri);

  return report.results[0] ? report.results[0].messages.map(toDiagnostic) : [];
}
Example #5
0
File: eslint.ts Project: otbe/ws
export async function eslintAsync(filePatterns = sourceFilePatterns) {
  const stats: Stats = engine.executeOnFiles([filePatterns]);

  const fixedFiles: string[] = [];
  await Promise.all(
    stats.results.map(async result => {
      const wasFixed = result.output !== undefined;
      if (wasFixed) {
        fixedFiles.push(result.filePath);
        await writeFileAsync(result.filePath, result.output);
      }
    })
  );

  const errorsCount = stats.errorCount;
  const errorsOrEmpty = await Promise.all(stats.results.map(formatter));
  const errors = errorsOrEmpty.filter(Boolean);
  return { errors, errorsCount, fixedFiles };
}
Example #6
0
 .filter(path => !cli.isPathIgnored(path))
Example #7
0
import minimatch = require('minimatch')

/* eslint no-undef: off */
/* REASON: not compatible with import = require() syntax. */

// No PR is too small to include a description of why you made a change
if (danger.github) {
  if (danger.github.pr.body.length < 10) {
    warn('Please include a description of your PR changes.')
  }
}

const filesToCheck = danger.git.created_files.concat(danger.git.modified_files)

// ESLint
const cli = new CLIEngine({})
const eslintPattern = '*.{js,jsx,ts,tsx}'
const filesToLint = filesToCheck
  .filter(path => minimatch(path, eslintPattern, { matchBase: true }))
  .filter(path => !cli.isPathIgnored(path))
const report = cli.executeOnFiles(filesToLint)
report.results.forEach(result => {
  const { filePath } = result
  result.messages.forEach(msg => {
    const { line, message, ruleId } = msg
    const rule = ruleId || 'N/A'
    const messageText = `${filePath} line ${line} – ${message} (${rule})`
    if (msg.severity === 1) {
      warn(messageText)
    } else if (msg.severity === 2) {
      fail(messageText)
Example #8
0
#!/usr/bin/env ts-node

import * as Path from 'path'
import chalk from 'chalk'

const { CLIEngine } = require('eslint')

const shouldFix = process.argv.indexOf('--fix') > -1
const eslint = new CLIEngine({
  cache: true,
  cwd: Path.dirname(__dirname),
  fix: shouldFix,
  rulePaths: [Path.join(__dirname, '..', 'eslint-rules')],
})

const report = eslint.executeOnFiles([
  './{script,eslint-rules}/**/*.{j,t}s?(x)',
  './tslint-rules/**/*.ts',
  './app/*.js',
  './app/{src,typings,test}/**/*.{j,t}s?(x)',
])

if (shouldFix) {
  CLIEngine.outputFixes(report)
}

console.log(eslint.getFormatter()(report.results))

if (report.errorCount > 0) {
  process.exitCode = 1
  console.error(