Skip to content

Commit

Permalink
Update linting setup, fix
Browse files Browse the repository at this point in the history
Correct missing dep
  • Loading branch information
kategengler committed Feb 7, 2023
1 parent 793a593 commit d228937
Show file tree
Hide file tree
Showing 18 changed files with 522 additions and 99 deletions.
10 changes: 5 additions & 5 deletions .eslintrc.json
Original file line number Diff line number Diff line change
@@ -1,21 +1,21 @@
{
"plugins": [
"node",
"n",
"mocha",
"prettier"
],
"extends": [
"eslint:recommended",
"plugin:node/recommended",
"plugin:n/recommended",
"plugin:mocha/recommended",
"plugin:prettier/recommended"
],
"rules": {
"prettier/prettier": "error",
"node/no-unpublished-require": "off",
"node/no-unpublished-import": "off"
"prettier/prettier": "error"
},
"parser": "@babel/eslint-parser",
"parserOptions": {
"requireConfigFile": false,
"ecmaVersion": 2020
},
"overrides": [
Expand Down
2 changes: 1 addition & 1 deletion lib/frontmatter-linter.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -155,7 +155,7 @@ export default class FrontmatterLinter {
}
return this.defaultSchema;
}
};
}

function formatErrors(errors) {
return errors.map((e) => {
Expand Down
2 changes: 1 addition & 1 deletion lib/frontmatter-updater.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ export default class FrontmatterUpdater {

return [frontmatterContent, content].join('\n');
}
};
}

function unionMerge(target, source) {
const combined = [...target, ...source];
Expand Down
2 changes: 1 addition & 1 deletion lib/result-reporter.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -27,4 +27,4 @@ export default class ResultReporter {
log(chalk.green(successMessage));
}
}
};
}
8 changes: 2 additions & 6 deletions lib/title.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import { toString } from 'mdast-util-to-string';
function topLevelHeaderText(tree) {
let heading;

visit(tree, 'heading', node => {
visit(tree, 'heading', (node) => {
if (node.depth !== 1) {
return;
}
Expand All @@ -18,11 +18,7 @@ function topLevelHeaderText(tree) {
}

export function title(markdown) {
const tree = unified()
.use(remarkParse)
.use(remarkGfm)
.use(remarkFrontmatter)
.parse(markdown)
const tree = unified().use(remarkParse).use(remarkGfm).use(remarkFrontmatter).parse(markdown);
const headingTree = topLevelHeaderText(tree);
return toString(headingTree);
}
6 changes: 4 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,13 @@
"author": "Katie Gengler",
"license": "MIT",
"devDependencies": {
"@babel/core": "^7.20.12",
"@babel/eslint-parser": "^7.19.1",
"chai": "^4.3.7",
"eslint": "^8.33.0",
"eslint-config-prettier": "^8.6.0",
"eslint-plugin-mocha": "^10.1.0",
"eslint-plugin-node": "^11.1.0",
"eslint-plugin-n": "^15.6.1",
"eslint-plugin-prettier": "^4.2.1",
"execa": "^6.1.0",
"mocha": "^10.2.0",
Expand All @@ -24,10 +26,10 @@
"@github-docs/frontmatter": "^1.3.1",
"chalk": "^5.2.0",
"deepmerge": "^4.3.0",
"mdast-util-to-string": "^3.1.1",
"remark-frontmatter": "^4.0.1",
"remark-gfm": "^3.0.1",
"remark-parse": "^10.0.1",
"remark-stringify": "^10.0.2",
"semver": "^7.3.8",
"simple-git": "^3.16.0",
"unified": "^10.1.2",
Expand Down
30 changes: 17 additions & 13 deletions scripts/check-filename-matches-pr.mjs
Original file line number Diff line number Diff line change
@@ -1,19 +1,23 @@
import yargs from 'yargs';
import { hideBin } from 'yargs/helpers'
import { hideBin } from 'yargs/helpers';
import ResultReporter from '../lib/result-reporter.mjs';

const argv = yargs(hideBin(process.argv)).command('* prNumber path', 'run check on file names', (yargs) => {
return yargs
.positional('pr_number', {
describe: 'The # of the current PR',
type: 'number',
})
.positional('path', {
describe: 'file path to run the lint on',
type: 'string',
})
.demandOption(['path', 'prNumber']);
}).argv;
const argv = yargs(hideBin(process.argv)).command(
'* prNumber path',
'run check on file names',
(yargs) => {
return yargs
.positional('pr_number', {
describe: 'The # of the current PR',
type: 'number',
})
.positional('path', {
describe: 'file path to run the lint on',
type: 'string',
})
.demandOption(['path', 'prNumber']);
}
).argv;

let results = [];
let parts = argv.path.split('/');
Expand Down
22 changes: 13 additions & 9 deletions scripts/find-next-stage.mjs
Original file line number Diff line number Diff line change
@@ -1,16 +1,20 @@
import yargs from 'yargs';
import { hideBin } from 'yargs/helpers'
import { hideBin } from 'yargs/helpers';
import { readFileSync } from 'node:fs';
import { frontmatter } from '../lib/frontmatter.mjs';

const argv = yargs(hideBin(process.argv)).command('* path', 'find the next stage for an RFC', (yargs) => {
return yargs
.positional('path', {
describe: 'file path of the RFC to check',
type: 'string',
})
.demandOption(['path']);
}).argv;
const argv = yargs(hideBin(process.argv)).command(
'* path',
'find the next stage for an RFC',
(yargs) => {
return yargs
.positional('path', {
describe: 'file path of the RFC to check',
type: 'string',
})
.demandOption(['path']);
}
).argv;

function main() {
const MergedStages = ['accepted', 'ready-for-release', 'released', 'recommended'];
Expand Down
4 changes: 2 additions & 2 deletions scripts/has-stage-changed.mjs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import yargs from 'yargs';
import { hideBin } from 'yargs/helpers'
import { hideBin } from 'yargs/helpers';
import simpleGit from 'simple-git';
import { readFileSync } from 'node:fs';
import { frontmatter } from '../lib/frontmatter.mjs';
Expand All @@ -24,7 +24,7 @@ const argv = yargs(hideBin(process.argv)).command(
const currentMarkdown = readFileSync(argv.path, 'utf8');
const { data: currentData } = frontmatter(currentMarkdown);
try {
const originalMarkdown = await simpleGit().show(`${argv.baseSha}:${argv.path}`)
const originalMarkdown = await simpleGit().show(`${argv.baseSha}:${argv.path}`);
const { data: originalData } = frontmatter(originalMarkdown);
if (originalData.stage !== currentData.stage) {
console.log(
Expand Down
3 changes: 1 addition & 2 deletions scripts/lint-rfc-frontmatter.mjs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import yargs from 'yargs';
import { hideBin } from 'yargs/helpers'
import { hideBin } from 'yargs/helpers';
import Linter from '../lib/frontmatter-linter.mjs';
import ResultReporter from '../lib/result-reporter.mjs';
import { readFileSync, readdirSync } from 'node:fs';
Expand All @@ -13,7 +13,6 @@ const argv = yargs(hideBin(process.argv)).command('* [paths..]', 'run lint on fi
.demandOption('paths');
}).argv;


const stages = readdirSync('./stages').map((filename) => filename.replace(/\.md$/, ''));
const teams = readdirSync('./teams').map((filename) => filename.replace(/\.md$/, ''));

Expand Down
22 changes: 13 additions & 9 deletions scripts/list-frontmatter.mjs
Original file line number Diff line number Diff line change
@@ -1,16 +1,20 @@
import yargs from 'yargs';
import { hideBin } from 'yargs/helpers'
import { hideBin } from 'yargs/helpers';
import { readFileSync } from 'node:fs';
import { frontmatter } from '../lib/frontmatter.mjs';

const argv = yargs(hideBin(process.argv)).command('* [paths..]', 'list frontmatter from files', (yargs) => {
return yargs
.positional('paths', {
describe: 'file paths to list frontmatter from',
type: 'array',
})
.demandOption('paths');
}).argv;
const argv = yargs(hideBin(process.argv)).command(
'* [paths..]',
'list frontmatter from files',
(yargs) => {
return yargs
.positional('paths', {
describe: 'file paths to list frontmatter from',
type: 'array',
})
.demandOption('paths');
}
).argv;

let results = [];
for (let path of argv.paths) {
Expand Down
3 changes: 1 addition & 2 deletions scripts/rfc-frontmatter.mjs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import yargs from 'yargs';
import { hideBin } from 'yargs/helpers'
import { hideBin } from 'yargs/helpers';
import { frontmatter } from '../lib/frontmatter.mjs';
import { readFileSync } from 'node:fs';

Expand All @@ -16,7 +16,6 @@ const argv = yargs(hideBin(process.argv)).command(
}
).argv;


let markdown = readFileSync(argv.path, 'utf8');
const { data, errors } = frontmatter(markdown);

Expand Down
2 changes: 1 addition & 1 deletion scripts/update-rfc-stage.mjs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import yargs from 'yargs';
import { hideBin } from 'yargs/helpers'
import { hideBin } from 'yargs/helpers';
import { readFileSync, writeFileSync } from 'node:fs';
import Updater from '../lib/frontmatter-updater.mjs';

Expand Down
11 changes: 5 additions & 6 deletions test/lib/title-test.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ My grand plans...
## Another heading
some stuff we will do
`
`;

const RfcWithBlocksInHeader = `---
stage: accepted
Expand All @@ -40,16 +40,15 @@ prs:
# Deprecate \`foo\` and \`bar\`; immediately
## Another heading
`
`;


describe('title', function() {
it('returns the contents of the first top-level header in the doc', async function() {
describe('title', function () {
it('returns the contents of the first top-level header in the doc', async function () {
let header = title(RFC);
expect(header).to.equal('My New RFC');
});

it('returns the text contents of the first top-level header in the doc when there are blocks', async function() {
it('returns the text contents of the first top-level header in the doc when there are blocks', async function () {
let header = title(RfcWithBlocksInHeader);
expect(header).to.equal('Deprecate foo and bar; immediately');
});
Expand Down
3 changes: 3 additions & 0 deletions test/scripts/has-stage-changed-test.mjs
Original file line number Diff line number Diff line change
@@ -1,7 +1,10 @@
describe('has-stage-changed', function () {
// eslint-disable-next-line mocha/no-skipped-tests
it.skip('succeeds when the stage in the current version of the RFC is different than that of the version at the baseSha', async function () {});

// eslint-disable-next-line mocha/no-skipped-tests
it.skip('fails when the stage in the current version of the RFC is the same as that in the baseSha', async function () {});

// eslint-disable-next-line mocha/no-skipped-tests
it.skip('fails when the RFC does not exist in the baseSha', async function () {});
});
4 changes: 2 additions & 2 deletions test/scripts/list-frontmatter-test.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ describe('list-frontmatter', function () {
prs: {
accepted: null,
},
title: "My New RFC"
title: 'My New RFC',
},
{
name: 'test/fixtures/0923-already-recommended.md',
Expand All @@ -35,7 +35,7 @@ describe('list-frontmatter', function () {
prs: {
accepted: null,
},
title: "My Completely finished RFC"
title: 'My Completely finished RFC',
},
]);
});
Expand Down
2 changes: 1 addition & 1 deletion test/scripts/rfc-frontmatter-test.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ describe('rfc-frontmatter', function () {
prs: {
accepted: null,
},
title: "My New RFC"
title: 'My New RFC',
});
});

Expand Down
Loading

0 comments on commit d228937

Please sign in to comment.