Skip to content

Commit

Permalink
Add test file
Browse files Browse the repository at this point in the history
  • Loading branch information
luc122c committed Apr 20, 2024
1 parent 0f404f8 commit 5b4eca1
Show file tree
Hide file tree
Showing 4 changed files with 80 additions and 1 deletion.
3 changes: 3 additions & 0 deletions packages/eslint-plugin/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -33,5 +33,8 @@
"dependencies": {
"@typescript-eslint/types": "^7.7.0",
"@typescript-eslint/utils": "^7.7.0"
},
"devDependencies": {
"@typescript-eslint/rule-tester": "^7.7.0"
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ export const rule = createRule<MessageIds, Options>({
const declarationType = exportNode.declaration?.type
if (declarationType === 'TSInterfaceDeclaration' || declarationType === 'TSTypeAliasDeclaration') return

// TODO: Check if it's an override, and the function above has a valid JSDoc
// TODO: Check if it's an overload, and the function above has a valid JSDoc

// Check if the exported node has a leading comment
const leadingComments = context.sourceCode.getCommentsBefore(exportNode)
Expand Down
52 changes: 52 additions & 0 deletions packages/eslint-plugin/tests/require-since.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
import { RuleTester } from '@typescript-eslint/rule-tester'
import { rule } from '../src/rules/require-jsdoc-since'

const ruleTester = new RuleTester({

Check failure on line 4 in packages/eslint-plugin/tests/require-since.test.ts

View workflow job for this annotation

GitHub Actions / ci (20, ubuntu-latest)

packages/eslint-plugin/tests/require-since.test.ts

Error: Missing definition for `afterAll` - you must set one using `RuleTester.afterAll` or there must be one defined globally as `afterAll`. ❯ Function.get afterAll [as afterAll] node_modules/.pnpm/@typescript-eslint+rule-tester@7.7.0_@eslint+eslintrc@3.0.2_eslint@9.0.0_typescript@5.4.5/node_modules/@typescript-eslint/rule-tester/src/TestFramework.ts:66:11 ❯ new RuleTester node_modules/.pnpm/@typescript-eslint+rule-tester@7.7.0_@eslint+eslintrc@3.0.2_eslint@9.0.0_typescript@5.4.5/node_modules/@typescript-eslint/rule-tester/src/RuleTester.ts:102:17 ❯ packages/eslint-plugin/tests/require-since.test.ts:4:20
parser: '@typescript-eslint/parser',
})

ruleTester.run('require-since', rule, {
valid: [
{
code: `
/** @since 1.0.0 */
function foo() {}
`,
},
{
code: `
/**
* @since 1.0.0
*/
function foo() {}
`,
// TODO: Check overloads
},
{
code: `
/**
* This is a comment.
* @param {string} foo - This is a foo.
* @since 1.0.0
*/
function foo(bar) {}
`,
},
],
invalid: [
{
code: `
/**
* This is a comment.
* @param {string} foo - This is a foo.
*/
function foo(bar) {}
`,
errors: [{ messageId: 'missing' }],
},
{
code: `function foo() {}`,
errors: [{ messageId: 'missing' }],
},
],
})
24 changes: 24 additions & 0 deletions pnpm-lock.yaml

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

0 comments on commit 5b4eca1

Please sign in to comment.