Skip to content

Commit

Permalink
docs: remove assertions
Browse files Browse the repository at this point in the history
  • Loading branch information
gajus committed Oct 13, 2023
1 parent b197579 commit bdaadca
Show file tree
Hide file tree
Showing 24 changed files with 6,552 additions and 4,592 deletions.
1,876 changes: 1,876 additions & 0 deletions README.md

Large diffs are not rendered by default.

4 changes: 2 additions & 2 deletions src/bin/addAssertions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -47,8 +47,8 @@ const getAssertions = () => {
const codes = require(filePath);

return {
invalid: _.map(codes.invalid, formatCodeSnippet),
valid: _.map(codes.valid, formatCodeSnippet),
invalid: _.map(codes.default.testCases.invalid, formatCodeSnippet),
valid: _.map(codes.default.testCases.valid, formatCodeSnippet),
};
});

Expand Down
31 changes: 30 additions & 1 deletion tests/RuleTester.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,9 @@
import { RuleTester } from '@typescript-eslint/rule-tester';
import {
type InvalidTestCase,
type ValidTestCase,
type RuleModule,
} from '@typescript-eslint/utils/ts-eslint';
import * as test from 'mocha';

if (typeof global.it === 'function') {
Expand All @@ -8,4 +13,28 @@ if (typeof global.it === 'function') {
RuleTester.describe = () => {};
}

export { RuleTester } from '@typescript-eslint/rule-tester';
export type TestCases<
TMessageIds extends string,
TOptions extends readonly unknown[] = [],
> = {
invalid: Array<InvalidTestCase<TMessageIds, TOptions>>;
valid: Array<ValidTestCase<TOptions>>;
};

export const createRuleTester = <
TMessageIds extends string,
TOptions extends readonly unknown[] = [],
>(
ruleName: string,
rule: RuleModule<TMessageIds, TOptions>,
parameters: ConstructorParameters<typeof RuleTester>[0],
testCases: TestCases<TMessageIds, TOptions>,
) => {
const ruleTester = new RuleTester(parameters);

ruleTester.run(ruleName, rule, testCases);

return {
testCases,
};
};
187 changes: 95 additions & 92 deletions tests/rules/destructuringPropertyNewline.ts
Original file line number Diff line number Diff line change
@@ -1,94 +1,97 @@
import rule from '../../src/rules/destructuringPropertyNewline';
import { RuleTester } from '../RuleTester';
import { createRuleTester } from '../RuleTester';

const ruleTester = new RuleTester({
parser: '@typescript-eslint/parser',
});

ruleTester.run('destructuring-property-newline', rule, {
invalid: [
{
code: 'const {a,b} = obj;',
errors: [
{
messageId: 'propertiesOnNewline',
},
],
output: 'const {a,\nb} = obj;',
},
{
code: 'const [a,b] = obj;',
errors: [
{
messageId: 'propertiesOnNewline',
},
],
output: 'const [a,\nb] = obj;',
},
{
code: 'const {a,b,c} = obj;',
errors: [
{
messageId: 'propertiesOnNewline',
},
{
messageId: 'propertiesOnNewline',
},
],
output: 'const {a,\nb,\nc} = obj;',
},
{
code: 'const {\na,b} = obj;',
errors: [
{
messageId: 'propertiesOnNewline',
},
],
output: 'const {\na,\nb} = obj;',
},
{
code: '({a,b}) => {};',
errors: [
{
messageId: 'propertiesOnNewline',
},
],
output: '({a,\nb}) => {};',
},
],
valid: [
{
code: 'const {a,\nb} = obj;',
},
{
code: 'const {a,b} = obj;',
options: [
{
allowAllPropertiesOnSameLine: true,
},
],
},
{
code: 'const [a,b] = obj;',
options: [
{
allowAllPropertiesOnSameLine: true,
},
],
},
{
code: 'const {a} = obj;',
},
{
code: 'const {\na\n} = obj;',
},
{
code: '({a,\nb}) => {};',
},
// This is a bug, but I don't see how to fix it given that element is `null` and we cannot
// use `sourceCode.getLastToken`.
{
code: 'const [a,,b] = obj;',
},
],
});
export default createRuleTester(
'destructuring-property-newline',
rule,
{
parser: '@typescript-eslint/parser',
},
{
invalid: [
{
code: 'const {a,b} = obj;',
errors: [
{
messageId: 'propertiesOnNewline',
},
],
output: 'const {a,\nb} = obj;',
},
{
code: 'const [a,b] = obj;',
errors: [
{
messageId: 'propertiesOnNewline',
},
],
output: 'const [a,\nb] = obj;',
},
{
code: 'const {a,b,c} = obj;',
errors: [
{
messageId: 'propertiesOnNewline',
},
{
messageId: 'propertiesOnNewline',
},
],
output: 'const {a,\nb,\nc} = obj;',
},
{
code: 'const {\na,b} = obj;',
errors: [
{
messageId: 'propertiesOnNewline',
},
],
output: 'const {\na,\nb} = obj;',
},
{
code: '({a,b}) => {};',
errors: [
{
messageId: 'propertiesOnNewline',
},
],
output: '({a,\nb}) => {};',
},
],
valid: [
{
code: 'const {a,\nb} = obj;',
},
{
code: 'const {a,b} = obj;',
options: [
{
allowAllPropertiesOnSameLine: true,
},
],
},
{
code: 'const [a,b] = obj;',
options: [
{
allowAllPropertiesOnSameLine: true,
},
],
},
{
code: 'const {a} = obj;',
},
{
code: 'const {\na\n} = obj;',
},
{
code: '({a,\nb}) => {};',
},
// This is a bug, but I don't see how to fix it given that element is `null` and we cannot
// use `sourceCode.getLastToken`.
{
code: 'const [a,,b] = obj;',
},
],
},
);
119 changes: 61 additions & 58 deletions tests/rules/exportSpecifierNewline.ts
Original file line number Diff line number Diff line change
@@ -1,61 +1,64 @@
import { AST_NODE_TYPES } from '@typescript-eslint/utils';
import rule from '../../src/rules/exportSpecifierNewline';
import { RuleTester } from '../RuleTester';
import { createRuleTester } from '../RuleTester';

const ruleTester = new RuleTester({
parser: '@typescript-eslint/parser',
});

ruleTester.run('export-specifier-newline', rule, {
invalid: [
{
code: 'const a = 1; const b = 2; const c = 3; export { a, b, c };',
errors: [
{
messageId: 'specifiersOnNewline',
type: AST_NODE_TYPES.ExportNamedDeclaration,
},
{
messageId: 'specifiersOnNewline',
type: AST_NODE_TYPES.ExportNamedDeclaration,
},
],
output: 'const a = 1; const b = 2; const c = 3; export { a,\nb,\nc };',
},
{
code: 'const a = 1; const b = 2; const c = 3; export { a, b, c, };',
errors: [
{
messageId: 'specifiersOnNewline',
type: AST_NODE_TYPES.ExportNamedDeclaration,
},
{
messageId: 'specifiersOnNewline',
type: AST_NODE_TYPES.ExportNamedDeclaration,
},
],
output: 'const a = 1; const b = 2; const c = 3; export { a,\nb,\nc, };',
},
{
code: 'const a = 1; const b = 2; export { a as default, b }',
errors: [
{
messageId: 'specifiersOnNewline',
type: AST_NODE_TYPES.ExportNamedDeclaration,
},
],
output: 'const a = 1; const b = 2; export { a as default,\nb }',
},
],
valid: [
{
code: "export { \n a,\nb,\nc\n } from 'foo'",
},
{
code: 'const a = 1; const b = 2; const c = 3; export { \n a,\nb,\nc\n };',
},
{
code: "export * from 'foo'",
},
],
});
export default createRuleTester(
'export-specifier-newline',
rule,
{
parser: '@typescript-eslint/parser',
},
{
invalid: [
{
code: 'const a = 1; const b = 2; const c = 3; export { a, b, c };',
errors: [
{
messageId: 'specifiersOnNewline',
type: AST_NODE_TYPES.ExportNamedDeclaration,
},
{
messageId: 'specifiersOnNewline',
type: AST_NODE_TYPES.ExportNamedDeclaration,
},
],
output: 'const a = 1; const b = 2; const c = 3; export { a,\nb,\nc };',
},
{
code: 'const a = 1; const b = 2; const c = 3; export { a, b, c, };',
errors: [
{
messageId: 'specifiersOnNewline',
type: AST_NODE_TYPES.ExportNamedDeclaration,
},
{
messageId: 'specifiersOnNewline',
type: AST_NODE_TYPES.ExportNamedDeclaration,
},
],
output: 'const a = 1; const b = 2; const c = 3; export { a,\nb,\nc, };',
},
{
code: 'const a = 1; const b = 2; export { a as default, b }',
errors: [
{
messageId: 'specifiersOnNewline',
type: AST_NODE_TYPES.ExportNamedDeclaration,
},
],
output: 'const a = 1; const b = 2; export { a as default,\nb }',
},
],
valid: [
{
code: "export { \n a,\nb,\nc\n } from 'foo'",
},
{
code: 'const a = 1; const b = 2; const c = 3; export { \n a,\nb,\nc\n };',
},
{
code: "export * from 'foo'",
},
],
},
);

0 comments on commit bdaadca

Please sign in to comment.