Skip to content

Commit 56339fd

Browse files
authored
Merge pull request #61 from fmulero/feature/align-markdownlinter
Markdown linter
2 parents e69f35d + b6a9273 commit 56339fd

17 files changed

+343
-123
lines changed

.github/PULL_REQUEST_TEMPLATE.md

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -7,32 +7,31 @@
77
88
-->
99

10-
**Description of the change**
10+
### Description of the change
1111

1212
<!-- Describe the scope of your change - i.e. what the change does. -->
1313

14-
**Benefits**
14+
### Benefits
1515

1616
<!-- What benefits will be realized by the code change? -->
1717

18-
**Possible drawbacks**
18+
### Possible drawbacks
1919

2020
<!-- Describe any known limitations with your change -->
2121

22-
**Applicable issues**
22+
### Applicable issues
2323

2424
<!-- Enter any applicable Issues here (You can reference an issue using #) -->
25-
- fixes #
25+
- fixes #
2626

27-
**Additional information**
27+
### Additional information
2828

2929
<!-- If there's anything else that's important and relevant to your pull
3030
request, mention that information here.-->
3131

32-
**Checklist**
32+
### Checklist
3333
<!-- [Place an '[X]' (no spaces) in all applicable fields. Please remove unrelated fields.] -->
3434
- [ ] Version bumped in `package.json` and `package-lock.json` according to [semver](http://semver.org/).
3535
- [ ] New features are documented in the README.md
3636
- [ ] New features contain a new test at the `tests` folder
3737
- [ ] All tests pass running `npm test`
38-

.github/workflows/ci-pipeline.yml

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,11 +25,16 @@ jobs:
2525
path: ~/.npm
2626
key: npm-${{ hashFiles('package-lock.json') }}
2727
restore-keys: npm-
28+
- id: markdownlint
29+
name: Install mardownlint
30+
run: npm install -g markdownlint-cli
2831
- id: npm-ci
2932
name: Clean install
3033
run: npm ci
31-
- name: Linter
32-
run: npm run lint
34+
- name: Linters
35+
run: |
36+
npm run lint
37+
markdownlint *.md **/*.md
3338
- name: Tests
3439
# Run tests if linter fails
3540
if: always() && steps.npm-ci.outcome == 'success'

.markdownlint.json

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
{
2+
"default": true,
3+
"MD013": false,
4+
"MD029": { "style": "ordered" },
5+
"MD033": false
6+
}

CODE_OF_CONDUCT.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,6 @@ If you are subjected to or witness unacceptable behavior, or have any other conc
1212

1313
If you have suggestions to improve this Code of Conduct, please submit an issue or PR.
1414

15-
**Attribution**
15+
## Attribution
1616

17-
This Code of Conduct is adapted from the Angular project available at this page: https://github.com/angular/code-of-conduct/blob/master/CODE_OF_CONDUCT.md
17+
This Code of Conduct is adapted from the Angular project available at this page: <https://github.com/angular/code-of-conduct/blob/master/CODE_OF_CONDUCT.md>

README.md

Lines changed: 16 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -44,8 +44,8 @@ The project has been developed and tested with node version `16.x`.
4444
Execute the following commands to install the tool:
4545

4646
```console
47-
$ git clone https://github.com/bitnami-labs/readme-generator-for-helm
48-
$ npm install ./readme-generator-for-helm
47+
git clone https://github.com/bitnami-labs/readme-generator-for-helm
48+
npm install ./readme-generator-for-helm
4949
```
5050

5151
Depending on how you installed NodeJS in your system, you may need to modify your `PATH` environment variable to be able to execute the tool.
@@ -55,26 +55,26 @@ Depending on how you installed NodeJS in your system, you may need to modify you
5555
Execute the following commands to create a single executable binary for the tool:
5656

5757
```console
58-
$ git clone https://github.com/bitnami-labs/readme-generator-for-helm
59-
$ cd ./readme-generator-for-helm
60-
$ npm install -g pkg
61-
$ pkg . -o readme-generator-for-helm
58+
git clone https://github.com/bitnami-labs/readme-generator-for-helm
59+
cd ./readme-generator-for-helm
60+
npm install -g pkg
61+
pkg . -o readme-generator-for-helm
6262
```
6363

6464
## Test
6565

6666
We use [Jest](https://jestjs.io) to implement the tests. In order to test your changes, execute the following command:
6767

6868
```console
69-
$ npm run-script test
69+
npm run-script test
7070
```
7171

7272
### Lint
7373

7474
After modifying the code execute the following command to pass the linter:
7575

7676
```console
77-
$ npm run-script lint
77+
npm run-script lint
7878
```
7979

8080
## Basic usage
@@ -167,11 +167,14 @@ The `-m (--metadata)` option has been renamed to `-s (--schema)` in order to pro
167167

168168
Copyright &copy; 2023 Bitnami
169169

170-
Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License.
171-
170+
Licensed under the Apache License, Version 2.0 (the "License");
171+
you may not use this file except in compliance with the License.
172172
You may obtain a copy of the License at
173173

174-
http://www.apache.org/licenses/LICENSE-2.0
174+
<http://www.apache.org/licenses/LICENSE-2.0>
175175

176-
Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
177-
See the License for the specific language governing permissions and limitations under the License.
176+
Unless required by applicable law or agreed to in writing, software
177+
distributed under the License is distributed on an "AS IS" BASIS,
178+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
179+
See the License for the specific language governing permissions and
180+
limitations under the License.

lib/render.js

Lines changed: 13 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -44,8 +44,8 @@ function renderSection({ name, description, parameters }, lineNumberSigns) {
4444
}
4545
if (parameters.length > 0) {
4646
sectionTable += createMarkdownTable(parameters); // section body parameters
47+
sectionTable += '\r\n';
4748
}
48-
sectionTable += '\r\n\n';
4949
return sectionTable;
5050
}
5151

@@ -76,37 +76,34 @@ function insertReadmeTable(readmeFilePath, sections, config) {
7676
/* eslint-disable prefer-destructuring */
7777
lineNumberSigns = match[1];
7878
paramsSectionLimits.push(i);
79-
console.log(`INFO: Found parameters section at: ${line}`);
79+
console.log(`INFO: Found parameters section at line: ${i + 1}`);
8080
}
8181
});
8282
if (paramsSectionLimits.length === 1) {
8383
// Find parameters section end
8484
let nextSectionFound = false;
8585
lines.slice(paramsSectionLimits[0] + 1).forEach((line, i) => {
8686
const nextSectionRegExp = new RegExp(`^${lineNumberSigns}\\s`); // Match same level section
87-
if (!nextSectionFound
88-
&& line.match(nextSectionRegExp)) {
89-
console.log(`INFO: Found section end at: ${line}`);
90-
paramsSectionLimits.push(i + paramsSectionLimits[0]);
87+
if (!nextSectionFound && line.match(nextSectionRegExp)) {
88+
const index = paramsSectionLimits[0] + 1 + i;
89+
console.log(`INFO: Found section end at line: ${index + 1}`);
90+
paramsSectionLimits.push(index);
9191
nextSectionFound = true;
92-
} else if (!nextSectionFound && paramsSectionLimits[0] + i + 2 === lines.length) {
93-
// The parameters section is the last section in the file
94-
paramsSectionLimits.push(i + 2 + paramsSectionLimits[0]);
95-
nextSectionFound = true;
96-
console.log('INFO: The parameters section seems to be the last section in the file');
9792
}
9893
});
94+
if (!nextSectionFound) {
95+
// The parameters section is the last section in the file
96+
paramsSectionLimits.push(lines.length);
97+
console.log('INFO: The parameters section seems to be the last section in the file');
98+
}
9999
// Detect last table-like line bottom to top to ignore description text between tables
100100
let lastTableLikeLineFound = false;
101-
let lastNonTableMatchInLine = 0;
102101
const endParamsSectionRegExp = new RegExp('(?!.*\\|).*\\S(?<!\\|.*)(?<!#.*)'); // Match non empty or with non table format lines
103102
lines.slice(paramsSectionLimits[0] + 1, paramsSectionLimits[1]).reverse().forEach((line, i) => {
104103
if (!lastTableLikeLineFound && line && !line.match(endParamsSectionRegExp)) {
105104
lastTableLikeLineFound = true;
106-
paramsSectionLimits[1] -= lastNonTableMatchInLine;
107-
console.log(`INFO: Last parameter table line found at: ${line}`);
108-
} else if (!lastTableLikeLineFound) {
109-
lastNonTableMatchInLine = i;
105+
paramsSectionLimits[1] -= i;
106+
console.log(`INFO: Last parameter table line found at line: ${paramsSectionLimits[1]}`);
110107
}
111108
});
112109
}

package-lock.json

Lines changed: 71 additions & 3 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@bitnami/readme-generator-for-helm",
3-
"version": "2.4.3",
3+
"version": "2.5.0",
44
"description": "Autogenerate READMEs tables and OpenAPI schemas for Helm Charts",
55
"main": "index.js",
66
"scripts": {
@@ -31,7 +31,8 @@
3131
"eslint": "^7.24.0",
3232
"eslint-config-airbnb-base": "^14.2.1",
3333
"eslint-plugin-import": "^2.22.1",
34-
"jest": "^29.2.1"
34+
"jest": "^29.2.1",
35+
"temp": "^0.9.4"
3536
},
3637
"directories": {
3738
"lib": "lib",

tests/basic.test.js

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
/* eslint-disable */
22
const fs = require('fs');
3+
const temp = require('temp').track();
34

5+
const expectedReadmeFirstExecution = `${__dirname}/expected-readme.first-execution.md`; // File that must result from executing the tool providing a readme file with only '### Parameters' and values
46
const testValuesPath = `${__dirname}/test-values.yaml`; // File where the content will end after the tool is executed
57
const testReadmeSubsequentSectionsPath = `${__dirname}/test-readme.md`; // File where the content will end after the tool is executed
68
const expectedReadmeSubsequentSectionsPath = `${__dirname}/expected-readme.md`; // File that must result from executing the tool providing the test README and values
@@ -13,6 +15,23 @@ const expectedSchemaPath = `${__dirname}/expected-schema.json`; // File that mus
1315

1416
const { runReadmeGenerator } = require('../index.js');
1517

18+
test('Check basic functionality. First execution', () => {
19+
// Create empty temp file with 'Parameters' section
20+
let tempFile = temp.path({ prefix: 'readme-generator'});
21+
let parametersHeader = "# Example\r\n\n## Parameters";
22+
fs.writeFileSync(tempFile, parametersHeader);
23+
// Run readme generator with the test files
24+
const options = {
25+
readme: tempFile,
26+
values: testValuesPath,
27+
};
28+
runReadmeGenerator(options);
29+
// Check the output is the expected one
30+
expect(fs.readFileSync(tempFile)).toEqual(fs.readFileSync(expectedReadmeFirstExecution));
31+
// Clean temporary file
32+
temp.cleanupSync();
33+
});
34+
1635
test('Check basic functionality', () => {
1736
// Run readme generator with the test files
1837
const options = {

0 commit comments

Comments
 (0)