Skip to content

Commit ddbebd1

Browse files
chinesedfansindresorhus
andcommittedNov 12, 2019
Add awesome/code-of-conduct rule (#76)
Co-Authored-By: Sindre Sorhus <sindresorhus@gmail.com>
1 parent c9b79f8 commit ddbebd1

24 files changed

+611
-10
lines changed
 

‎index.js

+26-8
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ const toVfile = require('to-vfile');
1313
const vfileReporterPretty = require('vfile-reporter-pretty');
1414
const config = require('./config');
1515
const findReadmeFile = require('./lib/find-readme-file');
16+
const codeOfConductRule = require('./rules/code-of-conduct');
1617

1718
const lint = options => {
1819
options = {
@@ -27,10 +28,24 @@ const lint = options => {
2728
return Promise.reject(new Error(`Couldn't find the file ${options.filename}`));
2829
}
2930

30-
const run = remark().use(options.config).process;
31-
const file = toVfile.readSync(path.resolve(readmeFile));
31+
const readmeVFile = toVfile.readSync(path.resolve(readmeFile));
32+
const {dirname} = readmeVFile;
33+
const processTasks = [{
34+
vfile: readmeVFile,
35+
plugins: options.config
36+
}];
37+
38+
const codeOfConductFile = globby.sync(['{.github/,}{code-of-conduct,code_of_conduct}.md'], {nocase: true, cwd: dirname})[0];
39+
if (codeOfConductFile) {
40+
const codeOfConductVFile = toVfile.readSync(path.resolve(dirname, codeOfConductFile));
41+
codeOfConductVFile.repoURL = options.repoURL;
42+
processTasks.push({
43+
vfile: codeOfConductVFile,
44+
plugins: [codeOfConductRule]
45+
});
46+
}
3247

33-
return pify(run)(file);
48+
return Promise.all(processTasks.map(({vfile, plugins}) => pify(remark().use(plugins).process)(vfile)));
3449
};
3550

3651
lint.report = async options => {
@@ -61,11 +76,16 @@ lint._report = async (options, spinner) => {
6176
throw new Error(`Unable to find valid readme for "${options.filename}"`);
6277
}
6378

79+
options.repoURL = options.filename;
6480
options.filename = readme;
6581
}
6682

67-
const file = await lint(options);
68-
const {messages} = file;
83+
const vfiles = await lint(options);
84+
const messages = [];
85+
for (const vfile of vfiles) {
86+
vfile.path = path.basename(vfile.path);
87+
messages.push(...vfile.messages);
88+
}
6989

7090
if (temp) {
7191
await rmfr(temp);
@@ -88,10 +108,8 @@ lint._report = async (options, spinner) => {
88108
spinner.fail();
89109
process.exitCode = 1;
90110

91-
file.path = path.basename(file.path);
92-
93111
const reporter = options.reporter || vfileReporterPretty;
94-
console.log(reporter([file]));
112+
console.log(reporter(vfiles));
95113
};
96114

97115
module.exports = lint;

‎lib/find-author-name.js

+14
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
'use strict';
2+
const parse = require('parse-github-url');
3+
const readPkg = require('read-pkg');
4+
5+
module.exports = ({repoURL, dirname}) => {
6+
if (repoURL) {
7+
return parse(repoURL).owner;
8+
}
9+
10+
try {
11+
const json = readPkg.sync({cwd: dirname});
12+
return parse(json.repository.url).owner;
13+
} catch (_) {}
14+
};

‎package.json

+2
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,9 @@
4949
"mdast-util-to-string": "^1.0.4",
5050
"meow": "^5.0.0",
5151
"ora": "^3.0.0",
52+
"parse-github-url": "^1.0.2",
5253
"pify": "^4.0.0",
54+
"read-pkg": "^5.1.1",
5355
"remark": "^10.0.1",
5456
"remark-lint": "^6.0.2",
5557
"remark-lint-blockquote-indentation": "^1.0.2",

‎readme.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -90,7 +90,7 @@ awesomeLint.report();
9090

9191
#### awesomeLint()
9292

93-
Returns a `Promise` for a [`VFile`](https://github.com/wooorm/vfile).
93+
Returns a `Promise` for a list of [`VFile`](https://github.com/wooorm/vfile) objects.
9494

9595
#### awesomeLint.report()
9696

‎rules/code-of-conduct.js

+33
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
'use strict';
2+
const find = require('unist-util-find');
3+
const rule = require('unified-lint-rule');
4+
const findAuthorName = require('../lib/find-author-name');
5+
6+
const authorName = 'sindresorhus';
7+
const authorEmail = 'sindresorhus@gmail.com';
8+
9+
module.exports = rule('remark-lint:awesome/code-of-conduct', (ast, file) => {
10+
if (ast.children.length === 0) {
11+
file.message('code-of-conduct.md file must not be empty');
12+
return;
13+
}
14+
15+
const placeholder = find(ast, node => (
16+
node.type === 'linkReference' &&
17+
node.label === 'INSERT EMAIL ADDRESS'
18+
));
19+
if (placeholder) {
20+
file.message('The email placeholder must be replaced with yours', placeholder);
21+
return;
22+
}
23+
24+
if (findAuthorName(file) !== authorName) {
25+
const email = find(ast, node => (
26+
node.type === 'text' &&
27+
node.value.includes(authorEmail)
28+
));
29+
if (email) {
30+
file.message('The default email must be replaced with yours', email);
31+
}
32+
}
33+
});

‎test/_lint.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import lint from '..';
22

33
export default async options => {
44
const result = await lint(options);
5-
return result.messages.map(error => ({
5+
return result.reduce((list, file) => list.concat(file.messages), []).map(error => ({
66
ruleId: error.ruleId,
77
message: error.message
88
}));

‎test/fixtures/code-of-conduct/error0/code-of-conduct.md

Whitespace-only changes.

‎test/fixtures/code-of-conduct/error0/readme.md

Whitespace-only changes.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,76 @@
1+
# Contributor Covenant Code of Conduct
2+
3+
## Our Pledge
4+
5+
In the interest of fostering an open and welcoming environment, we as
6+
contributors and maintainers pledge to making participation in our project and
7+
our community a harassment-free experience for everyone, regardless of age, body
8+
size, disability, ethnicity, sex characteristics, gender identity and expression,
9+
level of experience, education, socio-economic status, nationality, personal
10+
appearance, race, religion, or sexual identity and orientation.
11+
12+
## Our Standards
13+
14+
Examples of behavior that contributes to creating a positive environment
15+
include:
16+
17+
* Using welcoming and inclusive language
18+
* Being respectful of differing viewpoints and experiences
19+
* Gracefully accepting constructive criticism
20+
* Focusing on what is best for the community
21+
* Showing empathy towards other community members
22+
23+
Examples of unacceptable behavior by participants include:
24+
25+
* The use of sexualized language or imagery and unwelcome sexual attention or
26+
advances
27+
* Trolling, insulting/derogatory comments, and personal or political attacks
28+
* Public or private harassment
29+
* Publishing others' private information, such as a physical or electronic
30+
address, without explicit permission
31+
* Other conduct which could reasonably be considered inappropriate in a
32+
professional setting
33+
34+
## Our Responsibilities
35+
36+
Project maintainers are responsible for clarifying the standards of acceptable
37+
behavior and are expected to take appropriate and fair corrective action in
38+
response to any instances of unacceptable behavior.
39+
40+
Project maintainers have the right and responsibility to remove, edit, or
41+
reject comments, commits, code, wiki edits, issues, and other contributions
42+
that are not aligned to this Code of Conduct, or to ban temporarily or
43+
permanently any contributor for other behaviors that they deem inappropriate,
44+
threatening, offensive, or harmful.
45+
46+
## Scope
47+
48+
This Code of Conduct applies both within project spaces and in public spaces
49+
when an individual is representing the project or its community. Examples of
50+
representing a project or community include using an official project e-mail
51+
address, posting via an official social media account, or acting as an appointed
52+
representative at an online or offline event. Representation of a project may be
53+
further defined and clarified by project maintainers.
54+
55+
## Enforcement
56+
57+
Instances of abusive, harassing, or otherwise unacceptable behavior may be
58+
reported by contacting the project team at [INSERT EMAIL ADDRESS]. All
59+
complaints will be reviewed and investigated and will result in a response that
60+
is deemed necessary and appropriate to the circumstances. The project team is
61+
obligated to maintain confidentiality with regard to the reporter of an incident.
62+
Further details of specific enforcement policies may be posted separately.
63+
64+
Project maintainers who do not follow or enforce the Code of Conduct in good
65+
faith may face temporary or permanent repercussions as determined by other
66+
members of the project's leadership.
67+
68+
## Attribution
69+
70+
This Code of Conduct is adapted from the [Contributor Covenant][homepage], version 1.4,
71+
available at https://www.contributor-covenant.org/version/1/4/code-of-conduct.html
72+
73+
[homepage]: https://www.contributor-covenant.org
74+
75+
For answers to common questions about this code of conduct, see
76+
https://www.contributor-covenant.org/faq

‎test/fixtures/code-of-conduct/error1/readme.md

Whitespace-only changes.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,76 @@
1+
# Contributor Covenant Code of Conduct
2+
3+
## Our Pledge
4+
5+
In the interest of fostering an open and welcoming environment, we as
6+
contributors and maintainers pledge to making participation in our project and
7+
our community a harassment-free experience for everyone, regardless of age, body
8+
size, disability, ethnicity, sex characteristics, gender identity and expression,
9+
level of experience, education, socio-economic status, nationality, personal
10+
appearance, race, religion, or sexual identity and orientation.
11+
12+
## Our Standards
13+
14+
Examples of behavior that contributes to creating a positive environment
15+
include:
16+
17+
* Using welcoming and inclusive language
18+
* Being respectful of differing viewpoints and experiences
19+
* Gracefully accepting constructive criticism
20+
* Focusing on what is best for the community
21+
* Showing empathy towards other community members
22+
23+
Examples of unacceptable behavior by participants include:
24+
25+
* The use of sexualized language or imagery and unwelcome sexual attention or
26+
advances
27+
* Trolling, insulting/derogatory comments, and personal or political attacks
28+
* Public or private harassment
29+
* Publishing others' private information, such as a physical or electronic
30+
address, without explicit permission
31+
* Other conduct which could reasonably be considered inappropriate in a
32+
professional setting
33+
34+
## Our Responsibilities
35+
36+
Project maintainers are responsible for clarifying the standards of acceptable
37+
behavior and are expected to take appropriate and fair corrective action in
38+
response to any instances of unacceptable behavior.
39+
40+
Project maintainers have the right and responsibility to remove, edit, or
41+
reject comments, commits, code, wiki edits, issues, and other contributions
42+
that are not aligned to this Code of Conduct, or to ban temporarily or
43+
permanently any contributor for other behaviors that they deem inappropriate,
44+
threatening, offensive, or harmful.
45+
46+
## Scope
47+
48+
This Code of Conduct applies both within project spaces and in public spaces
49+
when an individual is representing the project or its community. Examples of
50+
representing a project or community include using an official project e-mail
51+
address, posting via an official social media account, or acting as an appointed
52+
representative at an online or offline event. Representation of a project may be
53+
further defined and clarified by project maintainers.
54+
55+
## Enforcement
56+
57+
Instances of abusive, harassing, or otherwise unacceptable behavior may be
58+
reported by contacting the project team at sindresorhus@gmail.com. All
59+
complaints will be reviewed and investigated and will result in a response that
60+
is deemed necessary and appropriate to the circumstances. The project team is
61+
obligated to maintain confidentiality with regard to the reporter of an incident.
62+
Further details of specific enforcement policies may be posted separately.
63+
64+
Project maintainers who do not follow or enforce the Code of Conduct in good
65+
faith may face temporary or permanent repercussions as determined by other
66+
members of the project's leadership.
67+
68+
## Attribution
69+
70+
This Code of Conduct is adapted from the [Contributor Covenant][homepage], version 1.4,
71+
available at https://www.contributor-covenant.org/version/1/4/code-of-conduct.html
72+
73+
[homepage]: https://www.contributor-covenant.org
74+
75+
For answers to common questions about this code of conduct, see
76+
https://www.contributor-covenant.org/faq

‎test/fixtures/code-of-conduct/error2/readme.md

Whitespace-only changes.

‎test/fixtures/code-of-conduct/valid0/readme.md

Whitespace-only changes.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,76 @@
1+
# Contributor Covenant Code of Conduct
2+
3+
## Our Pledge
4+
5+
In the interest of fostering an open and welcoming environment, we as
6+
contributors and maintainers pledge to making participation in our project and
7+
our community a harassment-free experience for everyone, regardless of age, body
8+
size, disability, ethnicity, sex characteristics, gender identity and expression,
9+
level of experience, education, socio-economic status, nationality, personal
10+
appearance, race, religion, or sexual identity and orientation.
11+
12+
## Our Standards
13+
14+
Examples of behavior that contributes to creating a positive environment
15+
include:
16+
17+
* Using welcoming and inclusive language
18+
* Being respectful of differing viewpoints and experiences
19+
* Gracefully accepting constructive criticism
20+
* Focusing on what is best for the community
21+
* Showing empathy towards other community members
22+
23+
Examples of unacceptable behavior by participants include:
24+
25+
* The use of sexualized language or imagery and unwelcome sexual attention or
26+
advances
27+
* Trolling, insulting/derogatory comments, and personal or political attacks
28+
* Public or private harassment
29+
* Publishing others' private information, such as a physical or electronic
30+
address, without explicit permission
31+
* Other conduct which could reasonably be considered inappropriate in a
32+
professional setting
33+
34+
## Our Responsibilities
35+
36+
Project maintainers are responsible for clarifying the standards of acceptable
37+
behavior and are expected to take appropriate and fair corrective action in
38+
response to any instances of unacceptable behavior.
39+
40+
Project maintainers have the right and responsibility to remove, edit, or
41+
reject comments, commits, code, wiki edits, issues, and other contributions
42+
that are not aligned to this Code of Conduct, or to ban temporarily or
43+
permanently any contributor for other behaviors that they deem inappropriate,
44+
threatening, offensive, or harmful.
45+
46+
## Scope
47+
48+
This Code of Conduct applies both within project spaces and in public spaces
49+
when an individual is representing the project or its community. Examples of
50+
representing a project or community include using an official project e-mail
51+
address, posting via an official social media account, or acting as an appointed
52+
representative at an online or offline event. Representation of a project may be
53+
further defined and clarified by project maintainers.
54+
55+
## Enforcement
56+
57+
Instances of abusive, harassing, or otherwise unacceptable behavior may be
58+
reported by contacting the project team at someone@gmail.com. All
59+
complaints will be reviewed and investigated and will result in a response that
60+
is deemed necessary and appropriate to the circumstances. The project team is
61+
obligated to maintain confidentiality with regard to the reporter of an incident.
62+
Further details of specific enforcement policies may be posted separately.
63+
64+
Project maintainers who do not follow or enforce the Code of Conduct in good
65+
faith may face temporary or permanent repercussions as determined by other
66+
members of the project's leadership.
67+
68+
## Attribution
69+
70+
This Code of Conduct is adapted from the [Contributor Covenant][homepage], version 1.4,
71+
available at https://www.contributor-covenant.org/version/1/4/code-of-conduct.html
72+
73+
[homepage]: https://www.contributor-covenant.org
74+
75+
For answers to common questions about this code of conduct, see
76+
https://www.contributor-covenant.org/faq

‎test/fixtures/code-of-conduct/valid1/readme.md

Whitespace-only changes.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,76 @@
1+
# Contributor Covenant Code of Conduct
2+
3+
## Our Pledge
4+
5+
In the interest of fostering an open and welcoming environment, we as
6+
contributors and maintainers pledge to making participation in our project and
7+
our community a harassment-free experience for everyone, regardless of age, body
8+
size, disability, ethnicity, sex characteristics, gender identity and expression,
9+
level of experience, education, socio-economic status, nationality, personal
10+
appearance, race, religion, or sexual identity and orientation.
11+
12+
## Our Standards
13+
14+
Examples of behavior that contributes to creating a positive environment
15+
include:
16+
17+
* Using welcoming and inclusive language
18+
* Being respectful of differing viewpoints and experiences
19+
* Gracefully accepting constructive criticism
20+
* Focusing on what is best for the community
21+
* Showing empathy towards other community members
22+
23+
Examples of unacceptable behavior by participants include:
24+
25+
* The use of sexualized language or imagery and unwelcome sexual attention or
26+
advances
27+
* Trolling, insulting/derogatory comments, and personal or political attacks
28+
* Public or private harassment
29+
* Publishing others' private information, such as a physical or electronic
30+
address, without explicit permission
31+
* Other conduct which could reasonably be considered inappropriate in a
32+
professional setting
33+
34+
## Our Responsibilities
35+
36+
Project maintainers are responsible for clarifying the standards of acceptable
37+
behavior and are expected to take appropriate and fair corrective action in
38+
response to any instances of unacceptable behavior.
39+
40+
Project maintainers have the right and responsibility to remove, edit, or
41+
reject comments, commits, code, wiki edits, issues, and other contributions
42+
that are not aligned to this Code of Conduct, or to ban temporarily or
43+
permanently any contributor for other behaviors that they deem inappropriate,
44+
threatening, offensive, or harmful.
45+
46+
## Scope
47+
48+
This Code of Conduct applies both within project spaces and in public spaces
49+
when an individual is representing the project or its community. Examples of
50+
representing a project or community include using an official project e-mail
51+
address, posting via an official social media account, or acting as an appointed
52+
representative at an online or offline event. Representation of a project may be
53+
further defined and clarified by project maintainers.
54+
55+
## Enforcement
56+
57+
Instances of abusive, harassing, or otherwise unacceptable behavior may be
58+
reported by contacting the project team at sindresorhus@gmail.com. All
59+
complaints will be reviewed and investigated and will result in a response that
60+
is deemed necessary and appropriate to the circumstances. The project team is
61+
obligated to maintain confidentiality with regard to the reporter of an incident.
62+
Further details of specific enforcement policies may be posted separately.
63+
64+
Project maintainers who do not follow or enforce the Code of Conduct in good
65+
faith may face temporary or permanent repercussions as determined by other
66+
members of the project's leadership.
67+
68+
## Attribution
69+
70+
This Code of Conduct is adapted from the [Contributor Covenant][homepage], version 1.4,
71+
available at https://www.contributor-covenant.org/version/1/4/code-of-conduct.html
72+
73+
[homepage]: https://www.contributor-covenant.org
74+
75+
For answers to common questions about this code of conduct, see
76+
https://www.contributor-covenant.org/faq
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
{
2+
"repository": "sindresorhus/awesome-lint"
3+
}

‎test/fixtures/code-of-conduct/valid2/readme.md

Whitespace-only changes.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,76 @@
1+
# Contributor Covenant Code of Conduct
2+
3+
## Our Pledge
4+
5+
In the interest of fostering an open and welcoming environment, we as
6+
contributors and maintainers pledge to making participation in our project and
7+
our community a harassment-free experience for everyone, regardless of age, body
8+
size, disability, ethnicity, sex characteristics, gender identity and expression,
9+
level of experience, education, socio-economic status, nationality, personal
10+
appearance, race, religion, or sexual identity and orientation.
11+
12+
## Our Standards
13+
14+
Examples of behavior that contributes to creating a positive environment
15+
include:
16+
17+
* Using welcoming and inclusive language
18+
* Being respectful of differing viewpoints and experiences
19+
* Gracefully accepting constructive criticism
20+
* Focusing on what is best for the community
21+
* Showing empathy towards other community members
22+
23+
Examples of unacceptable behavior by participants include:
24+
25+
* The use of sexualized language or imagery and unwelcome sexual attention or
26+
advances
27+
* Trolling, insulting/derogatory comments, and personal or political attacks
28+
* Public or private harassment
29+
* Publishing others' private information, such as a physical or electronic
30+
address, without explicit permission
31+
* Other conduct which could reasonably be considered inappropriate in a
32+
professional setting
33+
34+
## Our Responsibilities
35+
36+
Project maintainers are responsible for clarifying the standards of acceptable
37+
behavior and are expected to take appropriate and fair corrective action in
38+
response to any instances of unacceptable behavior.
39+
40+
Project maintainers have the right and responsibility to remove, edit, or
41+
reject comments, commits, code, wiki edits, issues, and other contributions
42+
that are not aligned to this Code of Conduct, or to ban temporarily or
43+
permanently any contributor for other behaviors that they deem inappropriate,
44+
threatening, offensive, or harmful.
45+
46+
## Scope
47+
48+
This Code of Conduct applies both within project spaces and in public spaces
49+
when an individual is representing the project or its community. Examples of
50+
representing a project or community include using an official project e-mail
51+
address, posting via an official social media account, or acting as an appointed
52+
representative at an online or offline event. Representation of a project may be
53+
further defined and clarified by project maintainers.
54+
55+
## Enforcement
56+
57+
Instances of abusive, harassing, or otherwise unacceptable behavior may be
58+
reported by contacting the project team at someone@gmail.com. All
59+
complaints will be reviewed and investigated and will result in a response that
60+
is deemed necessary and appropriate to the circumstances. The project team is
61+
obligated to maintain confidentiality with regard to the reporter of an incident.
62+
Further details of specific enforcement policies may be posted separately.
63+
64+
Project maintainers who do not follow or enforce the Code of Conduct in good
65+
faith may face temporary or permanent repercussions as determined by other
66+
members of the project's leadership.
67+
68+
## Attribution
69+
70+
This Code of Conduct is adapted from the [Contributor Covenant][homepage], version 1.4,
71+
available at https://www.contributor-covenant.org/version/1/4/code-of-conduct.html
72+
73+
[homepage]: https://www.contributor-covenant.org
74+
75+
For answers to common questions about this code of conduct, see
76+
https://www.contributor-covenant.org/faq

‎test/fixtures/code-of-conduct/valid3/readme.md

Whitespace-only changes.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,76 @@
1+
# Contributor Covenant Code of Conduct
2+
3+
## Our Pledge
4+
5+
In the interest of fostering an open and welcoming environment, we as
6+
contributors and maintainers pledge to making participation in our project and
7+
our community a harassment-free experience for everyone, regardless of age, body
8+
size, disability, ethnicity, sex characteristics, gender identity and expression,
9+
level of experience, education, socio-economic status, nationality, personal
10+
appearance, race, religion, or sexual identity and orientation.
11+
12+
## Our Standards
13+
14+
Examples of behavior that contributes to creating a positive environment
15+
include:
16+
17+
* Using welcoming and inclusive language
18+
* Being respectful of differing viewpoints and experiences
19+
* Gracefully accepting constructive criticism
20+
* Focusing on what is best for the community
21+
* Showing empathy towards other community members
22+
23+
Examples of unacceptable behavior by participants include:
24+
25+
* The use of sexualized language or imagery and unwelcome sexual attention or
26+
advances
27+
* Trolling, insulting/derogatory comments, and personal or political attacks
28+
* Public or private harassment
29+
* Publishing others' private information, such as a physical or electronic
30+
address, without explicit permission
31+
* Other conduct which could reasonably be considered inappropriate in a
32+
professional setting
33+
34+
## Our Responsibilities
35+
36+
Project maintainers are responsible for clarifying the standards of acceptable
37+
behavior and are expected to take appropriate and fair corrective action in
38+
response to any instances of unacceptable behavior.
39+
40+
Project maintainers have the right and responsibility to remove, edit, or
41+
reject comments, commits, code, wiki edits, issues, and other contributions
42+
that are not aligned to this Code of Conduct, or to ban temporarily or
43+
permanently any contributor for other behaviors that they deem inappropriate,
44+
threatening, offensive, or harmful.
45+
46+
## Scope
47+
48+
This Code of Conduct applies both within project spaces and in public spaces
49+
when an individual is representing the project or its community. Examples of
50+
representing a project or community include using an official project e-mail
51+
address, posting via an official social media account, or acting as an appointed
52+
representative at an online or offline event. Representation of a project may be
53+
further defined and clarified by project maintainers.
54+
55+
## Enforcement
56+
57+
Instances of abusive, harassing, or otherwise unacceptable behavior may be
58+
reported by contacting the project team at someone@gmail.com. All
59+
complaints will be reviewed and investigated and will result in a response that
60+
is deemed necessary and appropriate to the circumstances. The project team is
61+
obligated to maintain confidentiality with regard to the reporter of an incident.
62+
Further details of specific enforcement policies may be posted separately.
63+
64+
Project maintainers who do not follow or enforce the Code of Conduct in good
65+
faith may face temporary or permanent repercussions as determined by other
66+
members of the project's leadership.
67+
68+
## Attribution
69+
70+
This Code of Conduct is adapted from the [Contributor Covenant][homepage], version 1.4,
71+
available at https://www.contributor-covenant.org/version/1/4/code-of-conduct.html
72+
73+
[homepage]: https://www.contributor-covenant.org
74+
75+
For answers to common questions about this code of conduct, see
76+
https://www.contributor-covenant.org/faq

‎test/fixtures/code-of-conduct/valid4/readme.md

Whitespace-only changes.

‎test/lib/find-author-name.js

+11
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
import path from 'path';
2+
import test from 'ava';
3+
import findAuthorName from '../../lib/find-author-name';
4+
5+
test('findAuthorName - parse repo URL', t => {
6+
t.deepEqual(findAuthorName({repoURL: 'https://github.com/sindresorhus/awesome-lint'}), 'sindresorhus');
7+
});
8+
9+
test('findAuthorName - parse package.json', t => {
10+
t.deepEqual(findAuthorName({dirname: path.resolve(__dirname, '../../')}), 'sindresorhus');
11+
});

‎test/rules/code-of-conduct.js

+64
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
1+
import test from 'ava';
2+
import lint from '../_lint';
3+
4+
const config = {
5+
plugins: [
6+
// Don't set here, because it is only plugins for readme.md
7+
// require('../../rules/code-of-conduct')
8+
]
9+
};
10+
11+
test('code-of-conduct - invalid if empty', async t => {
12+
const messages = await lint({config, filename: 'test/fixtures/code-of-conduct/error0/readme.md'});
13+
t.deepEqual(messages, [
14+
{
15+
ruleId: 'awesome/code-of-conduct',
16+
message: 'code-of-conduct.md file must not be empty'
17+
}
18+
]);
19+
});
20+
21+
test('code-of-conduct - invalid if has placeholder', async t => {
22+
const messages = await lint({config, filename: 'test/fixtures/code-of-conduct/error1/readme.md'});
23+
t.deepEqual(messages, [
24+
{
25+
ruleId: 'awesome/code-of-conduct',
26+
message: 'The email placeholder must be replaced with yours'
27+
}
28+
]);
29+
});
30+
31+
test('code-of-conduct - invalid if just copyed', async t => {
32+
const messages = await lint({config, filename: 'test/fixtures/code-of-conduct/error2/readme.md'});
33+
t.deepEqual(messages, [
34+
{
35+
ruleId: 'awesome/code-of-conduct',
36+
message: 'The default email must be replaced with yours'
37+
}
38+
]);
39+
});
40+
41+
test('code-of-conduct - valid if missing', async t => {
42+
const messages = await lint({config, filename: 'test/fixtures/code-of-conduct/valid0/readme.md'});
43+
t.deepEqual(messages, []);
44+
});
45+
46+
test('code-of-conduct - valid if replaced', async t => {
47+
const messages = await lint({config, filename: 'test/fixtures/code-of-conduct/valid1/readme.md'});
48+
t.deepEqual(messages, []);
49+
});
50+
51+
test('code-of-conduct - valid if is sindresorhus himself', async t => {
52+
const messages = await lint({config, filename: 'test/fixtures/code-of-conduct/valid2/readme.md'});
53+
t.deepEqual(messages, []);
54+
});
55+
56+
test('code-of-conduct - valid with another file name', async t => {
57+
const messages = await lint({config, filename: 'test/fixtures/code-of-conduct/valid3/readme.md'});
58+
t.deepEqual(messages, []);
59+
});
60+
61+
test('code-of-conduct - valid with another folder', async t => {
62+
const messages = await lint({config, filename: 'test/fixtures/code-of-conduct/valid4/readme.md'});
63+
t.deepEqual(messages, []);
64+
});

0 commit comments

Comments
 (0)
Please sign in to comment.