Skip to content

Commit

Permalink
Merge pull request #61 from fmulero/feature/align-markdownlinter
Browse files Browse the repository at this point in the history
Markdown linter
  • Loading branch information
fmulero authored Feb 17, 2023
2 parents e69f35d + b6a9273 commit 56339fd
Show file tree
Hide file tree
Showing 17 changed files with 343 additions and 123 deletions.
15 changes: 7 additions & 8 deletions .github/PULL_REQUEST_TEMPLATE.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,32 +7,31 @@
-->

**Description of the change**
### Description of the change

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

**Benefits**
### Benefits

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

**Possible drawbacks**
### Possible drawbacks

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

**Applicable issues**
### Applicable issues

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

**Additional information**
### Additional information

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

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

9 changes: 7 additions & 2 deletions .github/workflows/ci-pipeline.yml
Original file line number Diff line number Diff line change
Expand Up @@ -25,11 +25,16 @@ jobs:
path: ~/.npm
key: npm-${{ hashFiles('package-lock.json') }}
restore-keys: npm-
- id: markdownlint
name: Install mardownlint
run: npm install -g markdownlint-cli
- id: npm-ci
name: Clean install
run: npm ci
- name: Linter
run: npm run lint
- name: Linters
run: |
npm run lint
markdownlint *.md **/*.md
- name: Tests
# Run tests if linter fails
if: always() && steps.npm-ci.outcome == 'success'
Expand Down
6 changes: 6 additions & 0 deletions .markdownlint.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{
"default": true,
"MD013": false,
"MD029": { "style": "ordered" },
"MD033": false
}
4 changes: 2 additions & 2 deletions CODE_OF_CONDUCT.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,6 @@ If you are subjected to or witness unacceptable behavior, or have any other conc

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

**Attribution**
## Attribution

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
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>
29 changes: 16 additions & 13 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -44,8 +44,8 @@ The project has been developed and tested with node version `16.x`.
Execute the following commands to install the tool:

```console
$ git clone https://github.com/bitnami-labs/readme-generator-for-helm
$ npm install ./readme-generator-for-helm
git clone https://github.com/bitnami-labs/readme-generator-for-helm
npm install ./readme-generator-for-helm
```

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.
Expand All @@ -55,26 +55,26 @@ Depending on how you installed NodeJS in your system, you may need to modify you
Execute the following commands to create a single executable binary for the tool:

```console
$ git clone https://github.com/bitnami-labs/readme-generator-for-helm
$ cd ./readme-generator-for-helm
$ npm install -g pkg
$ pkg . -o readme-generator-for-helm
git clone https://github.com/bitnami-labs/readme-generator-for-helm
cd ./readme-generator-for-helm
npm install -g pkg
pkg . -o readme-generator-for-helm
```

## Test

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

```console
$ npm run-script test
npm run-script test
```

### Lint

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

```console
$ npm run-script lint
npm run-script lint
```

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

Copyright &copy; 2023 Bitnami

Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License.

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

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

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.
See the License for the specific language governing permissions and limitations under the License.
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.
See the License for the specific language governing permissions and
limitations under the License.
29 changes: 13 additions & 16 deletions lib/render.js
Original file line number Diff line number Diff line change
Expand Up @@ -44,8 +44,8 @@ function renderSection({ name, description, parameters }, lineNumberSigns) {
}
if (parameters.length > 0) {
sectionTable += createMarkdownTable(parameters); // section body parameters
sectionTable += '\r\n';
}
sectionTable += '\r\n\n';
return sectionTable;
}

Expand Down Expand Up @@ -76,37 +76,34 @@ function insertReadmeTable(readmeFilePath, sections, config) {
/* eslint-disable prefer-destructuring */
lineNumberSigns = match[1];
paramsSectionLimits.push(i);
console.log(`INFO: Found parameters section at: ${line}`);
console.log(`INFO: Found parameters section at line: ${i + 1}`);
}
});
if (paramsSectionLimits.length === 1) {
// Find parameters section end
let nextSectionFound = false;
lines.slice(paramsSectionLimits[0] + 1).forEach((line, i) => {
const nextSectionRegExp = new RegExp(`^${lineNumberSigns}\\s`); // Match same level section
if (!nextSectionFound
&& line.match(nextSectionRegExp)) {
console.log(`INFO: Found section end at: ${line}`);
paramsSectionLimits.push(i + paramsSectionLimits[0]);
if (!nextSectionFound && line.match(nextSectionRegExp)) {
const index = paramsSectionLimits[0] + 1 + i;
console.log(`INFO: Found section end at line: ${index + 1}`);
paramsSectionLimits.push(index);
nextSectionFound = true;
} else if (!nextSectionFound && paramsSectionLimits[0] + i + 2 === lines.length) {
// The parameters section is the last section in the file
paramsSectionLimits.push(i + 2 + paramsSectionLimits[0]);
nextSectionFound = true;
console.log('INFO: The parameters section seems to be the last section in the file');
}
});
if (!nextSectionFound) {
// The parameters section is the last section in the file
paramsSectionLimits.push(lines.length);
console.log('INFO: The parameters section seems to be the last section in the file');
}
// Detect last table-like line bottom to top to ignore description text between tables
let lastTableLikeLineFound = false;
let lastNonTableMatchInLine = 0;
const endParamsSectionRegExp = new RegExp('(?!.*\\|).*\\S(?<!\\|.*)(?<!#.*)'); // Match non empty or with non table format lines
lines.slice(paramsSectionLimits[0] + 1, paramsSectionLimits[1]).reverse().forEach((line, i) => {
if (!lastTableLikeLineFound && line && !line.match(endParamsSectionRegExp)) {
lastTableLikeLineFound = true;
paramsSectionLimits[1] -= lastNonTableMatchInLine;
console.log(`INFO: Last parameter table line found at: ${line}`);
} else if (!lastTableLikeLineFound) {
lastNonTableMatchInLine = i;
paramsSectionLimits[1] -= i;
console.log(`INFO: Last parameter table line found at line: ${paramsSectionLimits[1]}`);
}
});
}
Expand Down
74 changes: 71 additions & 3 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 3 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@bitnami/readme-generator-for-helm",
"version": "2.4.3",
"version": "2.5.0",
"description": "Autogenerate READMEs tables and OpenAPI schemas for Helm Charts",
"main": "index.js",
"scripts": {
Expand Down Expand Up @@ -31,7 +31,8 @@
"eslint": "^7.24.0",
"eslint-config-airbnb-base": "^14.2.1",
"eslint-plugin-import": "^2.22.1",
"jest": "^29.2.1"
"jest": "^29.2.1",
"temp": "^0.9.4"
},
"directories": {
"lib": "lib",
Expand Down
19 changes: 19 additions & 0 deletions tests/basic.test.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
/* eslint-disable */
const fs = require('fs');
const temp = require('temp').track();

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
const testValuesPath = `${__dirname}/test-values.yaml`; // File where the content will end after the tool is executed
const testReadmeSubsequentSectionsPath = `${__dirname}/test-readme.md`; // File where the content will end after the tool is executed
const expectedReadmeSubsequentSectionsPath = `${__dirname}/expected-readme.md`; // File that must result from executing the tool providing the test README and values
Expand All @@ -13,6 +15,23 @@ const expectedSchemaPath = `${__dirname}/expected-schema.json`; // File that mus

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

test('Check basic functionality. First execution', () => {
// Create empty temp file with 'Parameters' section
let tempFile = temp.path({ prefix: 'readme-generator'});
let parametersHeader = "# Example\r\n\n## Parameters";
fs.writeFileSync(tempFile, parametersHeader);
// Run readme generator with the test files
const options = {
readme: tempFile,
values: testValuesPath,
};
runReadmeGenerator(options);
// Check the output is the expected one
expect(fs.readFileSync(tempFile)).toEqual(fs.readFileSync(expectedReadmeFirstExecution));
// Clean temporary file
temp.cleanupSync();
});

test('Check basic functionality', () => {
// Run readme generator with the test files
const options = {
Expand Down
Loading

0 comments on commit 56339fd

Please sign in to comment.