How to use the eslint.CLIEngine function in eslint

To help you get started, we’ve selected a few eslint 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 izelnakri / mber / lib / worker-pool / worker.js View on Github external
// Console.log(workerReference, chalk.yellow('transpiling JS/TS'));

      Promise.all(
        fileNames.map((fileName) => transpileToES5(fileName, applicationName, projectRoot))
      )
        .then((result) => parentPort.postMessage(result))
        .catch((error) => {
          Console.log(workerReference, chalk.red('ERROR OCCURED DURING TRANSPILATION:'));
          console.log(error);

          parentPort.postMessage({ error: normalizeError(error) });
        });
    } else if (action === 'LINT_JS') {
      Console.log(workerReference, chalk.yellow('linting JS/TS'));

      global.jsLinter = global.jsLinter || new eslint.CLIEngine();

      try {
        const timer = countTime();

        lintJavaScript(fileNames, global.jsLinter);

        Console.log(
          workerReference,
          chalk.green(`lint passes successfully in ${formatTimePassed(timer.stop())}`)
        );

        parentPort.postMessage(true);
      } catch (error) {
        console.log('ERROR IS', error);

        parentPort.postMessage({ error: normalizeError(error) });
github sikidamjanovic / cowrite / node_modules / react-scripts / config / webpack.config.js View on Github external
baseConfig: (() => {
                  const eslintCli = new eslint.CLIEngine();
                  let eslintConfig;
                  try {
                    eslintConfig = eslintCli.getConfigForFile(paths.appIndexJs);
                  } catch (e) {
                    // A config couldn't be found.
                  }

                  // We allow overriding the config only if the env variable is set
                  if (process.env.EXTEND_ESLINT === 'true' && eslintConfig) {
                    return eslintConfig;
                  } else {
                    return {
                      extends: [require.resolve('eslint-config-react-app')],
                    };
                  }
                })(),
github salesforce / eslint-config-lwc / test / base.js View on Github external
it('should load properly base config', () => {
        const cli = new eslint.CLIEngine({
            useEslintrc: false,
            baseConfig: {
                extends: '@salesforce/eslint-config-lwc/base',
            },
        });

        const report = cli.executeOnText(`
            import { api } from 'lwc';
            class Foo {
                @api({ param: true })
                foo;
            }
        `);

        const { messages } = report.results[0];
        assert.equal(messages.length, 1);
github BenoitZugmeyer / eslint-plugin-html / src / __tests__ / plugin.js View on Github external
function execute(file, baseConfig) {
  if (!baseConfig) baseConfig = {}

  const cli = new CLIEngine({
    extensions: ["html"],
    baseConfig: {
      settings: baseConfig.settings,
      rules: Object.assign(
        {
          "no-console": 2,
        },
        baseConfig.rules
      ),
      globals: baseConfig.globals,
      env: baseConfig.env,
      parserOptions: baseConfig.parserOptions,
    },
    ignore: false,
    useEslintrc: false,
    fix: baseConfig.fix,
github codice / ddf / ui / packages / ace / lib / lint.js View on Github external
})
      html('a').each((i, elem) => {
        if (elem.attribs.href) {
          reportHtml(file, 'a', 'href', elem.attribs.href)
        }
      })
      html('script').each((i, elem) => {
        if (elem.attribs.src) {
          reportHtml(file, 'script', 'src', elem.attribs.src)
        }
      })
    } catch (e) {
      console.error(e)
    }
  })
  var jsResults = new CLIEngine().executeOnFiles(['./'])
  jsResults.results = jsResults.results.filter(function(result) {
    delete result.source
    return result.errorCount
  })
  if (jsResults.errorCount || htmlResults.errorCount) {
    throw new Error(
      'Non-relative paths found' +
        '\n' +
        JSON.stringify(jsResults, null, 2) +
        '\n' +
        JSON.stringify(htmlResults, null, 2)
    )
  }
}
github hapijs / lab / lib / linter / index.js View on Github external
if (!Fs.existsSync('.eslintrc.js') &&
        !Fs.existsSync('.eslintrc.yaml') &&
        !Fs.existsSync('.eslintrc.yml') &&
        !Fs.existsSync('.eslintrc.json') &&
        !Fs.existsSync('.eslintrc')) {
        configuration.configFile = Path.join(__dirname, '.eslintrc.js');
    }

    if (options) {
        Hoek.merge(configuration, options, true, false);
    }

    let results;
    try {
        const engine = new Eslint.CLIEngine(configuration);
        results = engine.executeOnFiles(['.']);
    }
    catch (ex) {
        results = {
            results: [{ messages: [ex] }]
        };
    }


    return results.results.map((result) => {

        const transformed = {
            filename: result.filePath
        };

        if (result.hasOwnProperty('output')) {
github traveloka / javascript / packages / marlint / index.js View on Github external
);

    if (!workspacePath) {
      const engine = new CLIEngine(defaultOpts.eslint);
      return engine.executeOnText(str, filePath);
    }

    const workspaceOpts = pkgConf.sync('marlint', { cwd: workspacePath });
    const mergedOpts = {
      eslint: {
        ...defaultOpts.eslint,
        rules: { ...defaultOpts.eslint.rules, ...workspaceOpts.rules },
        globals: defaultOpts.eslint.globals.concat(workspaceOpts.globals || []),
      },
    };
    const engine = new CLIEngine(mergedOpts.eslint);
    return engine.executeOnText(str, filePath);
  }

  const engine = new CLIEngine(defaultOpts.eslint);
  return engine.executeOnText(str, filePath);
};
github quinkennedy / travis-github-lint-status / index.js View on Github external
function processFiles(glob){
  var cli = new ESLint.CLIEngine();
  var report = cli.executeOnFiles(cli.resolveFileGlobPatterns([glob]));
  return report;
}
github mysticatea / eslint-plugin / scripts / generate-configs.js View on Github external
* DON'T EDIT THIS FILE WHICH WAS GENERATED BY './scripts/generate-configs.js'.
 */
"use strict"

module.exports = {
${fs
    .readdirSync(path.resolve(__dirname, "../lib/configs"))
    .map(fileName => path.basename(fileName, ".js"))
    .filter(id => !id.startsWith("_"))
    .map(id => `    "${id}": require("./configs/${id}"),`)
    .join("\n")}
}
`
)

const linter = new CLIEngine({ fix: true })
const result = linter.executeOnFiles([targetFile])
CLIEngine.outputFixes(result)