Skip to content
Merged
Show file tree
Hide file tree
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 16 additions & 0 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@ const vfileReporterPretty = require('vfile-reporter-pretty');
const config = require('./config');
const findReadmeFile = require('./lib/find-readme-file');

const rGithubRepo = /^https:\/\/github\.com\/[^/]+\/[^/]+$/;

const lint = options => {
options = {
config,
Expand All @@ -34,9 +36,23 @@ const lint = options => {

lint.report = async options => {
const spinner = ora('Linting').start();

try {
await lint._report(options, spinner);
} catch (error) {
spinner.fail(error.message);
process.exitCode = 1;
}
};

lint._report = async (options, spinner) => {
let temp = null;

if (isUrl(options.filename)) {
if (!rGithubRepo.test(options.filename)) {
throw new Error(`Invalid Github repository url: ${options.filename}`);
}

temp = tempy.directory();
await pify(gitClone)(options.filename, temp);

Expand Down
14 changes: 14 additions & 0 deletions test/cli.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,3 +7,17 @@ test('main', async t => {
/Missing Awesome badge/
);
});

test('main - non-exsitent file', async t => {
await t.throwsAsync(
execa.stderr('./cli.js', ['test/fixtures/non-exsitent.md']),
/Couldn't find the file/
);
});

test('main - invalid Github repository', async t => {
await t.throwsAsync(
execa.stderr('./cli.js', ['https://github.com/sindresorhus/awesome-lint/blob/master/readme.md']),
/Invalid Github repository url/
);
});