本文整理汇总了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;未经允许,请勿转载。 |
请发表评论