Skip to content

Commit

Permalink
Output and check errors lines (#92)
Browse files Browse the repository at this point in the history
  • Loading branch information
chinesedfan authored and sindresorhus committed Nov 24, 2019
1 parent 1e34ff4 commit 4a1c9f3
Show file tree
Hide file tree
Showing 15 changed files with 93 additions and 29 deletions.
1 change: 1 addition & 0 deletions test/_lint.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import lint from '..';
export default async options => {
const result = await lint(options);
return result.reduce((list, file) => list.concat(file.messages), []).map(error => ({
line: error.line,
ruleId: error.ruleId,
message: error.message
}));
Expand Down
3 changes: 3 additions & 0 deletions test/rules/badge.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ test('badge - missing', async t => {
const messages = await lint({config, filename: 'test/fixtures/badge/error0.md'});
t.deepEqual(messages, [
{
line: 1,
ruleId: 'awesome-badge',
message: 'Missing Awesome badge after the main heading'
}
Expand All @@ -22,6 +23,7 @@ test('badge - incorrect source', async t => {
const messages = await lint({config, filename: 'test/fixtures/badge/error1.md'});
t.deepEqual(messages, [
{
line: 1,
ruleId: 'awesome-badge',
message: 'Invalid badge source'
}
Expand All @@ -32,6 +34,7 @@ test('badge - incorrect source raw git', async t => {
const messages = await lint({config, filename: 'test/fixtures/badge/error2.md'});
t.deepEqual(messages, [
{
line: 1,
ruleId: 'awesome-badge',
message: 'Invalid badge source'
}
Expand Down
3 changes: 3 additions & 0 deletions test/rules/code-of-conduct.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ test('code-of-conduct - invalid if empty', async t => {
const messages = await lint({config, filename: 'test/fixtures/code-of-conduct/error0/readme.md'});
t.deepEqual(messages, [
{
line: null,
ruleId: 'awesome-code-of-conduct',
message: 'code-of-conduct.md file must not be empty'
}
Expand All @@ -22,6 +23,7 @@ test('code-of-conduct - invalid if has placeholder', async t => {
const messages = await lint({config, filename: 'test/fixtures/code-of-conduct/error1/readme.md'});
t.deepEqual(messages, [
{
line: 58,
ruleId: 'awesome-code-of-conduct',
message: 'The email placeholder must be replaced with yours'
}
Expand All @@ -32,6 +34,7 @@ test('code-of-conduct - invalid if just copyed', async t => {
const messages = await lint({config, filename: 'test/fixtures/code-of-conduct/error2/readme.md'});
t.deepEqual(messages, [
{
line: 57,
ruleId: 'awesome-code-of-conduct',
message: 'The default email must be replaced with yours'
}
Expand Down
2 changes: 2 additions & 0 deletions test/rules/contributing.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ test('contributing - missing', async t => {
const messages = await lint({config, filename: 'test/fixtures/contributing/error0/readme.md'});
t.deepEqual(messages, [
{
line: null,
ruleId: 'awesome-contributing',
message: 'Missing file contributing.md'
}
Expand All @@ -21,6 +22,7 @@ test('contributing - empty', async t => {
const messages = await lint({config, filename: 'test/fixtures/contributing/error1/readme.md'});
t.deepEqual(messages, [
{
line: null,
ruleId: 'awesome-contributing',
message: 'contributing.md file must not be empty'
}
Expand Down
2 changes: 2 additions & 0 deletions test/rules/git-repo-age.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ test.serial('git-repo-age - error invalid git repo', async t => {
const messages = await lint({config, filename: 'test/fixtures/git-repo-age/0.md'});
t.deepEqual(messages, [
{
line: null,
ruleId: 'awesome-git-repo-age',
message: 'Awesome list must reside in a valid deep-cloned Git repository (see https://github.com/sindresorhus/awesome-lint#tip for more information)'
}
Expand All @@ -49,6 +50,7 @@ test.serial('git-repo-age - error repo is not old enough', async t => {
const messages = await lint({config, filename: 'test/fixtures/git-repo-age/0.md'});
t.deepEqual(messages, [
{
line: null,
ruleId: 'awesome-git-repo-age',
message: 'Git repository must be at least 30 days old'
}
Expand Down
10 changes: 10 additions & 0 deletions test/rules/github.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ test.serial('github - error invalid git repo', async t => {
const messages = await lint({config, filename: 'test/fixtures/github/0.md'});
t.deepEqual(messages, [
{
line: null,
ruleId: 'awesome-github',
message: 'Awesome list must reside in a valid git repository'
}
Expand Down Expand Up @@ -56,9 +57,11 @@ test.serial('github - repo without description and license', async t => {
const messages = await lint({config, filename: 'test/fixtures/github/0.md'});
t.deepEqual(messages, [
{
line: null,
ruleId: 'awesome-github',
message: 'The repository should have a description'
}, {
line: null,
ruleId: 'awesome-github',
message: 'License was not detected by GitHub'
}
Expand Down Expand Up @@ -88,6 +91,7 @@ test.serial('github - missing topic awesome-list', async t => {
const messages = await lint({config, filename: 'test/fixtures/github/0.md'});
t.deepEqual(messages, [
{
line: null,
ruleId: 'awesome-github',
message: 'The repository should have "awesome-list" as a GitHub topic'
}
Expand Down Expand Up @@ -117,6 +121,7 @@ test.serial('github - missing topic awesome', async t => {
const messages = await lint({config, filename: 'test/fixtures/github/0.md'});
t.deepEqual(messages, [
{
line: null,
ruleId: 'awesome-github',
message: 'The repository should have "awesome" as a GitHub topic'
}
Expand All @@ -133,6 +138,7 @@ test.serial('github - remote origin is an GitLab repo', async t => {
const messages = await lint({config, filename: 'test/fixtures/github/0.md'});
t.deepEqual(messages, [
{
line: null,
ruleId: 'awesome-github',
message: 'Repository should be on GitHub'
}
Expand All @@ -156,6 +162,7 @@ test.serial('github - invalid token', async t => {
const messages = await lint({config, filename: 'test/fixtures/github/0.md'});
t.deepEqual(messages, [
{
line: null,
ruleId: 'awesome-github',
message: 'Unauthorized access or token is invalid'
}
Expand Down Expand Up @@ -184,6 +191,7 @@ test.serial('github - API rate limit exceeded with token', async t => {
const messages = await lint({config, filename: 'test/fixtures/github/0.md'});
t.deepEqual(messages, [
{
line: null,
ruleId: 'awesome-github',
message: 'API rate limit of 5000 requests per hour exceeded'
}
Expand Down Expand Up @@ -212,6 +220,7 @@ test.serial('github - API rate limit exceeded without token', async t => {
const messages = await lint({config, filename: 'test/fixtures/github/0.md'});
t.deepEqual(messages, [
{
line: null,
ruleId: 'awesome-github',
message: 'API rate limit of 60 requests per hour exceeded. Use a personal token to increase the number of requests'
}
Expand All @@ -236,6 +245,7 @@ test.serial('github - API offline', async t => {
const messages = await lint({config, filename: 'test/fixtures/github/0.md'});
t.deepEqual(messages, [
{
line: null,
ruleId: 'awesome-github',
message: 'There was a problem trying to connect to GitHub: getaddrinfo ENOTFOUND api.github.com api.github.com:443'
}
Expand Down
4 changes: 4 additions & 0 deletions test/rules/heading.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ test('heading - missing', async t => {
const messages = await lint({config, filename: 'test/fixtures/heading/error0.md'});
t.deepEqual(messages, [
{
line: 1,
ruleId: 'awesome-heading',
message: 'Missing main list heading'
}
Expand All @@ -22,6 +23,7 @@ test('heading - not in title case', async t => {
const messages = await lint({config, filename: 'test/fixtures/heading/error1.md'});
t.deepEqual(messages, [
{
line: 1,
ruleId: 'awesome-heading',
message: 'Main heading must be in title case'
}
Expand All @@ -32,6 +34,7 @@ test('heading - more than one heading', async t => {
const messages = await lint({config, filename: 'test/fixtures/heading/error2.md'});
t.deepEqual(messages, [
{
line: 3,
ruleId: 'awesome-heading',
message: 'List can only have one heading'
}
Expand All @@ -42,6 +45,7 @@ test('heading - depth is bigger than 1', async t => {
const messages = await lint({config, filename: 'test/fixtures/heading/error3.md'});
t.deepEqual(messages, [
{
line: 1,
ruleId: 'awesome-heading',
message: 'Main list heading must be of depth 1'
}
Expand Down
5 changes: 5 additions & 0 deletions test/rules/license.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ test('license - missing', async t => {
const messages = await lint({config, filename: 'test/fixtures/license/error0.md'});
t.deepEqual(messages, [
{
line: 1,
ruleId: 'awesome-license',
message: 'Missing License section'
}
Expand All @@ -27,6 +28,7 @@ test('license - empty', async t => {
// message: 'Remove empty section: "License"'
// },
{
line: 11,
ruleId: 'awesome-license',
message: 'License must not be empty'
}
Expand All @@ -37,6 +39,7 @@ test('license - not last section', async t => {
const messages = await lint({config, filename: 'test/fixtures/license/error2.md'});
t.deepEqual(messages, [
{
line: 11,
ruleId: 'awesome-license',
message: 'License must be the last section'
}
Expand All @@ -47,6 +50,7 @@ test('license - incorrect heading depth', async t => {
const messages = await lint({config, filename: 'test/fixtures/license/error3.md'});
t.deepEqual(messages, [
{
line: 11,
ruleId: 'awesome-license',
message: 'License section must be at heading depth 2'
}
Expand All @@ -57,6 +61,7 @@ test('license - png image', async t => {
const messages = await lint({config, filename: 'test/fixtures/license/error4.md'});
t.deepEqual(messages, [
{
line: 3,
ruleId: 'awesome-license',
message: 'License image must be SVG'
}
Expand Down
10 changes: 5 additions & 5 deletions test/rules/list-item.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,16 +18,16 @@ test('list-item - invalid', async t => {
t.snapshot(messages);
});

test('list-item - invalid sublist punctuation', async t => {
const messages = await lint({config, filename: 'test/fixtures/list-item/3.md'});
t.snapshot(messages);
});

test('list-item - valid ignoring Contents section', async t => {
const messages = await lint({config, filename: 'test/fixtures/list-item/2.md'});
t.deepEqual(messages, []);
});

test('list-item - invalid sublist punctuation', async t => {
const messages = await lint({config, filename: 'test/fixtures/list-item/3.md'});
t.snapshot(messages);
});

test('list-item - disable, enable, and ignore comments', async t => {
const messages = await lint({config, filename: 'test/fixtures/list-item/4.md'});
t.snapshot(messages);
Expand Down
2 changes: 2 additions & 0 deletions test/rules/no-ci-badge.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,12 @@ test('no-ci-badge - missing', async t => {
const messages = await lint({config, filename: 'test/fixtures/no-ci-badge/0.md'});
t.deepEqual(messages, [
{
line: 1,
ruleId: 'awesome-no-ci-badge',
message: 'Readme must not contain CI badge'
},
{
line: 3,
ruleId: 'awesome-no-ci-badge',
message: 'Readme must not contain CI badge'
}
Expand Down
Loading

0 comments on commit 4a1c9f3

Please sign in to comment.