Repository: sindresorhus/awesome-lint
Pull request #111 (2020-07-27 09:15:25)

Fix location matching of contributing.md and code-of-conduct.md files
This PR fix the use of optional folder glob pattern to locate contribution and code of conduct guidelines. Also adds fixtures and unittests.

kdeldycke: BTW, it seems curly braces pattern (i.e. `{.github/,}`) are somewhat broken in `minimatch`: https://github.com/isaacs/minimatch/issues/126

Patch:
diff --git a/index.js b/index.js
index c513b7c..e7f2141 100644
--- a/index.js
+++ b/index.js
@@ -35,7 +35,7 @@ const lint = options => {
 		plugins: options.config
 	}];
 
-	const codeOfConductFile = globby.sync(['{.github/,}{code-of-conduct,code_of_conduct}.md'], {nocase: true, cwd: dirname})[0];
+	const codeOfConductFile = globby.sync(['{code-of-conduct,code_of_conduct}.md', '.github/{code-of-conduct,code_of_conduct}.md'], {nocase: true, cwd: dirname})[0];
 	if (codeOfConductFile) {
 		const codeOfConductVFile = toVfile.readSync(path.resolve(dirname, codeOfConductFile));
 		codeOfConductVFile.repoURL = options.repoURL;
diff --git a/rules/contributing.js b/rules/contributing.js
index 693be33..7f44b37 100644
--- a/rules/contributing.js
+++ b/rules/contributing.js
@@ -7,7 +7,7 @@ const rule = require('unified-lint-rule');
 module.exports = rule('remark-lint:awesome-contributing', (ast, file) => {
 	const {dirname} = file;
 
-	const contributingFile = globby.sync(['{.github/,}contributing.md'], {nocase: true, cwd: dirname})[0];
+	const contributingFile = globby.sync(['contributing.md', '.github/contributing.md'], {nocase: true, cwd: dirname})[0];
 	// TODO: This doesn't work on Linux for some reason. Investigate and then open an issue on `fast-glob`.
 	// const contributingFile = globby.sync('contributing.md', {case: false, cwd: dirname})[0];
 


Test patch:
diff --git a/test/fixtures/contributing/valid2/.github/CONTRIBUTING.md b/test/fixtures/contributing/valid2/.github/CONTRIBUTING.md
new file mode 100644
index 0000000..df1fc73
--- /dev/null
+++ b/test/fixtures/contributing/valid2/.github/CONTRIBUTING.md
@@ -0,0 +1,30 @@
+# Contribution Guidelines
+
+Please note that this project is released with a [Contributor Code of Conduct](code-of-conduct.md). By participating in this project you agree to abide by its terms.
+
+---
+
+Ensure your pull request adheres to the following guidelines:
+
+- **If you just created something, wait at least 7 days before submitting.** This is to give it some time to mature and ensure it's not just a publish-and-forget type of project.
+- If you submit a project that is similar to an existing project in the list, argue how it's better.
+- Search previous suggestions before making a new one, as yours may be a duplicate.
+- Suggested packages should be tested and documented.
+- Make an individual pull request for each suggestion.
+- Use the following format: `[package](link) - Description.`
+- Additions should be added to the bottom of the relevant category.
+- Link to the GitHub repo, not npmjs.com.
+- Keep descriptions short and simple, but descriptive.
+- Don't mention `Node.js` in the description as it's implied.
+- Start the description with a capital and end with a full stop/period.
+- Don't start the description with `A` or `An`.
+- Check your spelling and grammar.
+- Make sure your text editor is set to remove trailing whitespace.
+- The pull request should have a useful title and include a link to the package and why it should be included.
+- New categories or improvements to the existing categorization are welcome, but should be done in a separate pull request.
+
+Thank you for your suggestions!
+
+### Updating your PR
+
+A lot of times, making a PR adhere to the standards above can be difficult. If the maintainers notice anything that we'd like changed, we'll ask you to edit your PR before we merge it. If you're not sure how to do that, [here is a guide](https://github.com/RichardLitt/knowledge/blob/master/github/amending-a-commit-guide.md) on the different ways you can update your PR so that we can merge it.
diff --git a/test/fixtures/contributing/valid2/readme.md b/test/fixtures/contributing/valid2/readme.md
new file mode 100644
index 0000000..e69de29
diff --git a/test/fixtures/contributing/valid3/.github/contributing.md b/test/fixtures/contributing/valid3/.github/contributing.md
new file mode 100644
index 0000000..df1fc73
--- /dev/null
+++ b/test/fixtures/contributing/valid3/.github/contributing.md
@@ -0,0 +1,30 @@
+# Contribution Guidelines
+
+Please note that this project is released with a [Contributor Code of Conduct](code-of-conduct.md). By participating in this project you agree to abide by its terms.
+
+---
+
+Ensure your pull request adheres to the following guidelines:
+
+- **If you just created something, wait at least 7 days before submitting.** This is to give it some time to mature and ensure it's not just a publish-and-forget type of project.
+- If you submit a project that is similar to an existing project in the list, argue how it's better.
+- Search previous suggestions before making a new one, as yours may be a duplicate.
+- Suggested packages should be tested and documented.
+- Make an individual pull request for each suggestion.
+- Use the following format: `[package](link) - Description.`
+- Additions should be added to the bottom of the relevant category.
+- Link to the GitHub repo, not npmjs.com.
+- Keep descriptions short and simple, but descriptive.
+- Don't mention `Node.js` in the description as it's implied.
+- Start the description with a capital and end with a full stop/period.
+- Don't start the description with `A` or `An`.
+- Check your spelling and grammar.
+- Make sure your text editor is set to remove trailing whitespace.
+- The pull request should have a useful title and include a link to the package and why it should be included.
+- New categories or improvements to the existing categorization are welcome, but should be done in a separate pull request.
+
+Thank you for your suggestions!
+
+### Updating your PR
+
+A lot of times, making a PR adhere to the standards above can be difficult. If the maintainers notice anything that we'd like changed, we'll ask you to edit your PR before we merge it. If you're not sure how to do that, [here is a guide](https://github.com/RichardLitt/knowledge/blob/master/github/amending-a-commit-guide.md) on the different ways you can update your PR so that we can merge it.
diff --git a/test/fixtures/contributing/valid3/readme.md b/test/fixtures/contributing/valid3/readme.md
new file mode 100644
index 0000000..e69de29
diff --git a/test/rules/contributing.js b/test/rules/contributing.js
index 72c7d39..498deb4 100644
--- a/test/rules/contributing.js
+++ b/test/rules/contributing.js
@@ -38,3 +38,13 @@ test('contributing - valid contributing.md', async t => {
 	const messages = await lint({config, filename: 'test/fixtures/contributing/valid1/readme.md'});
 	t.deepEqual(messages, []);
 });
+
+test('contributing - valid .github/CONTRIBUTING.md', async t => {
+	const messages = await lint({config, filename: 'test/fixtures/contributing/valid2/readme.md'});
+	t.deepEqual(messages, []);
+});
+
+test('contributing - valid .github/contributing.md', async t => {
+	const messages = await lint({config, filename: 'test/fixtures/contributing/valid3/readme.md'});
+	t.deepEqual(messages, []);
+});