當前位置: 首頁>>代碼示例>>TypeScript>>正文


TypeScript eslint.CLIEngine類代碼示例

本文整理匯總了TypeScript中eslint.CLIEngine的典型用法代碼示例。如果您正苦於以下問題:TypeScript CLIEngine類的具體用法?TypeScript CLIEngine怎麽用?TypeScript CLIEngine使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。


在下文中一共展示了CLIEngine類的8個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的TypeScript代碼示例。

示例1: function

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)
  }
}
開發者ID:YangShaoQun,項目名稱:taro,代碼行數:16,代碼來源:eslintValidator.ts

示例2: doValidation

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) : [];
}
開發者ID:tiravata,項目名稱:vetur,代碼行數:11,代碼來源:htmlValidation.ts

示例3: require

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)
開發者ID:bemusic,項目名稱:bemuse,代碼行數:31,代碼來源:dangerfile.ts

示例4: require

#!/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(
開發者ID:Ahskys,項目名稱:desktop,代碼行數:31,代碼來源:eslint.ts

示例5: Program

} = () => {
  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')
            }
          }
        }
      }
    }
  }
}
開發者ID:YangShaoQun,項目名稱:taro,代碼行數:28,代碼來源:eslint.ts

示例6: Program

} = () => {
  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')
            }
          }
        }
      }
    }
  }
}
開發者ID:AlloyTeam,項目名稱:Nuclear,代碼行數:28,代碼來源:eslint.ts

示例7: writeFileAsync

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 };
}
開發者ID:otbe,項目名稱:ws,代碼行數:19,代碼來源:eslint.ts

示例8:

 .filter(path => !cli.isPathIgnored(path))
開發者ID:bemusic,項目名稱:bemuse,代碼行數:1,代碼來源:dangerfile.ts


注:本文中的eslint.CLIEngine類示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。