-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add
postprocess
config file option (useful for applying prettier fo…
…rmatting) (#285)
- Loading branch information
Showing
8 changed files
with
176 additions
and
28 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
24 changes: 24 additions & 0 deletions
24
test/lib/generate/__snapshots__/option-postprocess-test.ts.snap
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
// Jest Snapshot v1, https://goo.gl/fbAQLP | ||
|
||
exports[`generate (postprocess option) basic calls the postprocessor 1`] = ` | ||
"## Rules | ||
<!-- begin auto-generated rules list --> | ||
| Name | | ||
| :----------------------------- | | ||
| [no-foo](docs/rules/no-foo.md) | | ||
<!-- end auto-generated rules list --> | ||
Located at README.md" | ||
`; | ||
|
||
exports[`generate (postprocess option) basic calls the postprocessor 2`] = ` | ||
"# test/no-foo | ||
<!-- end auto-generated rule header --> | ||
Located at docs/rules/no-foo.md" | ||
`; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
import { generate } from '../../../lib/generator.js'; | ||
import mockFs from 'mock-fs'; | ||
import { dirname, resolve, relative } from 'node:path'; | ||
import { fileURLToPath } from 'node:url'; | ||
import { readFileSync } from 'node:fs'; | ||
import { jest } from '@jest/globals'; | ||
|
||
const __dirname = dirname(fileURLToPath(import.meta.url)); | ||
|
||
const PATH_NODE_MODULES = resolve(__dirname, '..', '..', '..', 'node_modules'); | ||
|
||
describe('generate (postprocess option)', function () { | ||
describe('basic', function () { | ||
beforeEach(function () { | ||
mockFs({ | ||
'package.json': JSON.stringify({ | ||
name: 'eslint-plugin-test', | ||
exports: 'index.js', | ||
type: 'module', | ||
}), | ||
|
||
'index.js': ` | ||
export default { | ||
rules: { | ||
'no-foo': { | ||
meta: {}, | ||
create(context) {} | ||
}, | ||
}, | ||
};`, | ||
|
||
'README.md': '## Rules\n', | ||
|
||
'docs/rules/no-foo.md': '', | ||
|
||
// Needed for some of the test infrastructure to work. | ||
node_modules: mockFs.load(PATH_NODE_MODULES), | ||
}); | ||
}); | ||
|
||
afterEach(function () { | ||
mockFs.restore(); | ||
jest.resetModules(); | ||
}); | ||
|
||
it('calls the postprocessor', async function () { | ||
await generate('.', { | ||
postprocess: (content, path) => | ||
[ | ||
content, | ||
'', | ||
`Located at ${relative('.', path).replace(/\\/gu, '/')}`, // Always use forward slashes in the path so the snapshot is right even when testing on Windows. | ||
].join('\n'), | ||
}); | ||
expect(readFileSync('README.md', 'utf8')).toMatchSnapshot(); | ||
expect(readFileSync('docs/rules/no-foo.md', 'utf8')).toMatchSnapshot(); | ||
}); | ||
}); | ||
}); |