refactor: remove sub-eslintrc, fix more lint errors (#7530)

This commit is contained in:
Joshua Chen 2022-05-30 14:49:51 +08:00 committed by GitHub
parent f443e992b9
commit 9023b7740c
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
20 changed files with 129 additions and 92 deletions

View file

@ -0,0 +1,9 @@
foo
`bar`
```js
baz
```
export const toc = 1;

View file

@ -1,5 +1,18 @@
// Jest Snapshot v1, https://goo.gl/fbAQLP
exports[`toc remark plugin does not overwrite TOC var if no TOC 1`] = `
"foo
\`bar\`
\`\`\`js
baz
\`\`\`
export const toc = 1;
"
`;
exports[`toc remark plugin escapes inline code 1`] = `
"export const toc = [
{

View file

@ -30,6 +30,14 @@ describe('toc remark plugin', () => {
expect(result).toMatchSnapshot();
});
// A very implicit API: we allow users to hand-write the toc variable. It will
// get overwritten in most cases, but until we find a better way, better keep
// supporting this
it('does not overwrite TOC var if no TOC', async () => {
const result = await processFixture('no-heading-with-toc-export');
expect(result).toMatchSnapshot();
});
it('works on non text phrasing content', async () => {
const result = await processFixture('non-text-content');
expect(result).toMatchSnapshot();

View file

@ -89,8 +89,10 @@ export default function plugin(): Transformer {
const {children} = root as Parent<Literal>;
const targetIndex = getOrCreateExistingTargetIndex(children);
children[targetIndex]!.value = `export const ${name} = ${stringifyObject(
headings,
)};`;
if (headings.length) {
children[targetIndex]!.value = `export const ${name} = ${stringifyObject(
headings,
)};`;
}
};
}