Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Lint function does not accept a git URL #187

Open
discombobulateme opened this issue Oct 26, 2020 · 2 comments
Open

Lint function does not accept a git URL #187

discombobulateme opened this issue Oct 26, 2020 · 2 comments

Comments

@discombobulateme
Copy link

Issue Report

When using repolinter as a dependency, I do not receive the lint.results

Expected Behavior

  1. To receive all tests passed using default ruleset after running lint.results
  2. To receive the same results as when running repolinter in bash

GitHub repository used as a model repository tested: Sauce Labs OSPO new project template

Actual Behavior

Receive status: 'NOT_PASSED_ERROR', passed: false

Screen Shot 2020-10-26 at 6 39 37 PM

Steps to Reproduce the Issue

  1. Use repolinter in bash: repolinter lint -g https://github.com/saucelabs/new-project.git
  2. Use repolinter as a dependency in a node project npm i repolinter
  3. Import it into a file
const repolinter = require('repolinter')

async function main() {
 
  const url = 'https://github.com/saucelabs/new-project.git'

  const repolinterConnect = await repolinter.lint(url)
  console.log(repolinterConnect.results)

  const results = repolinterConnect.results
    .filter(r => r.lintResult && !r.lintResult.passed)
    .map(r => r.lintResult.message)
  // console.log(`In the repo ${url} there are a few missing things: ${results}\n`)
}

main()
  1. run file node <file-name>.js
  2. compare results
@prototypicalpro
Copy link
Collaborator

prototypicalpro commented Oct 26, 2020

This is because the lint API does not accept a URL, but the CLI does. If you would like to use the lint API on a git repository, I would recommend cloning the repository locally and then using the lint function on the cloned directory. This functionality is actually implemented in the CLI here:

// temporarily clone a git repo to lint
if (argv.git) {
tmpDir = await fs.promises.mkdtemp(path.join(os.tmpdir(), 'repolinter-'))
const result = await git.clone(argv.directory, tmpDir)
if (result) {
console.error(result)
process.exitCode = 1
rimraf(tmpDir, () => {})
return
}
}
// run the linter
const output = await repolinter.lint(tmpDir || path.resolve(process.cwd(), argv.directory), argv.allowPaths, rulesetParsed || argv.rulesetFile, argv.dryRun)

@prototypicalpro prototypicalpro changed the title Unable to lint using repolinter as dependency Lint function does not accept a git URL Oct 26, 2020
@discombobulateme
Copy link
Author

Thank you for your super fast feedback! :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants