eslint-plugin-expect-type
Advanced tools
Comparing version 0.5.0 to 0.5.1
@@ -29,3 +29,2 @@ "use strict"; | ||
const typeAssertions = /* @__PURE__ */ new Map(); | ||
const duplicates = []; | ||
const syntaxErrors = []; | ||
@@ -53,5 +52,2 @@ const twoSlashAssertions = []; | ||
case "Error": | ||
if (errorLines.has(line)) { | ||
duplicates.push(line); | ||
} | ||
errorLines.add(line); | ||
@@ -62,7 +58,3 @@ break; | ||
if (expected) { | ||
if (typeAssertions.delete(line)) { | ||
duplicates.push(line); | ||
} else { | ||
typeAssertions.set(line, { assertionType: "manual", expected }); | ||
} | ||
typeAssertions.set(line, { assertionType: "manual", expected }); | ||
} else { | ||
@@ -79,11 +71,7 @@ syntaxErrors.push({ | ||
if (snapshotName) { | ||
if (typeAssertions.delete(line)) { | ||
duplicates.push(line); | ||
} else { | ||
typeAssertions.set(line, { | ||
assertionType: "snapshot", | ||
expected: (0, import_snapshot.getTypeSnapshot)(sourceFile.fileName, snapshotName), | ||
snapshotName | ||
}); | ||
} | ||
typeAssertions.set(line, { | ||
assertionType: "snapshot", | ||
expected: (0, import_snapshot.getTypeSnapshot)(sourceFile.fileName, snapshotName), | ||
snapshotName | ||
}); | ||
} else { | ||
@@ -116,3 +104,2 @@ syntaxErrors.push({ | ||
return { | ||
duplicates, | ||
errorLines, | ||
@@ -119,0 +106,0 @@ syntaxErrors, |
type Assertion = ManualAssertion | SnapshotAssertion | TwoSlashAssertion; | ||
interface Assertions { | ||
/** | ||
* Lines with more than one assertion (these are errors). | ||
*/ | ||
readonly duplicates: readonly number[]; | ||
/** | ||
* Lines with an $ExpectError. | ||
@@ -9,0 +5,0 @@ */ |
@@ -6,3 +6,2 @@ import { ESLintUtils } from '@typescript-eslint/utils'; | ||
FileIsNotIncludedInTSConfig: string; | ||
Multiple$ExpectTypeAssertions: string; | ||
OrphanAssertion: string; | ||
@@ -18,3 +17,3 @@ SyntaxError: string; | ||
} | ||
declare const expect: ESLintUtils.RuleModule<"ExpectedErrorNotFound" | "FileIsNotIncludedInTSConfig" | "Multiple$ExpectTypeAssertions" | "OrphanAssertion" | "SyntaxError" | "TypesDoNotMatch" | "TypeSnapshotDoNotMatch" | "TypeSnapshotNotFound", [Options], { | ||
declare const expect: ESLintUtils.RuleModule<"ExpectedErrorNotFound" | "FileIsNotIncludedInTSConfig" | "OrphanAssertion" | "SyntaxError" | "TypesDoNotMatch" | "TypeSnapshotDoNotMatch" | "TypeSnapshotNotFound", [Options], { | ||
requiresTypeChecking?: boolean; | ||
@@ -21,0 +20,0 @@ }, ESLintUtils.RuleListener>; |
@@ -45,3 +45,2 @@ "use strict"; | ||
FileIsNotIncludedInTSConfig: 'Expected to find a file "{{ fileName }}" present.', | ||
Multiple$ExpectTypeAssertions: "This line has 2 or more $ExpectType assertions.", | ||
OrphanAssertion: "Can not match a node to this assertion.", | ||
@@ -62,26 +61,6 @@ SyntaxError: "Syntax Error: {{ message }}", | ||
const sourceFile = program.getSourceFile(fileName); | ||
if (!sourceFile) { | ||
context.report({ | ||
data: { | ||
fileName | ||
}, | ||
loc: { | ||
column: 0, | ||
line: 1 | ||
}, | ||
messageId: "FileIsNotIncludedInTSConfig" | ||
}); | ||
return {}; | ||
} | ||
if (!/\$Expect(?:Type|Error|\?)|\^\?/.test(sourceFile.text)) { | ||
return {}; | ||
} | ||
const { | ||
duplicates, | ||
errorLines, | ||
syntaxErrors, | ||
twoSlashAssertions, | ||
typeAssertions | ||
} = (0, import_parseAssertions.parseAssertions)(sourceFile); | ||
reportDuplicates(context, duplicates); | ||
const { errorLines, syntaxErrors, twoSlashAssertions, typeAssertions } = (0, import_parseAssertions.parseAssertions)(sourceFile); | ||
reportNotFoundErrors(context, errorLines, program, sourceFile); | ||
@@ -94,3 +73,9 @@ reportSyntaxErrors(context, syntaxErrors); | ||
); | ||
reportUnmetExpectations(context, options, unmetExpectations, sourceFile); | ||
reportUnmetExpectations( | ||
context, | ||
fileName, | ||
options, | ||
unmetExpectations, | ||
sourceFile | ||
); | ||
reportUnusedAssertions(context, unusedAssertions); | ||
@@ -122,13 +107,2 @@ return {}; | ||
}); | ||
function reportDuplicates(context, duplicates) { | ||
for (const line of duplicates) { | ||
context.report({ | ||
loc: { | ||
column: 0, | ||
line: line + 1 | ||
}, | ||
messageId: "Multiple$ExpectTypeAssertions" | ||
}); | ||
} | ||
} | ||
function reportNotFoundErrors(context, errorLines, program, sourceFile) { | ||
@@ -165,3 +139,3 @@ const diagnostics = import_typescript.default.getPreEmitDiagnostics(program, sourceFile); | ||
} | ||
function reportUnmetExpectations(context, options, unmetExpectations, sourceFile) { | ||
function reportUnmetExpectations(context, fileName, options, unmetExpectations, sourceFile) { | ||
for (const { actual, assertion, node } of unmetExpectations) { | ||
@@ -190,5 +164,4 @@ const templateDescriptor = { | ||
(0, import_snapshot.updateTypeSnapshot)( | ||
// TODO: Once ESLint <8 support is removed, soon | ||
// eslint-disable-next-line @typescript-eslint/no-deprecated | ||
context.filename || context.getFilename(), | ||
// TODO: Once ESLint <8 support is removed, context.filename | ||
fileName, | ||
snapshotName, | ||
@@ -195,0 +168,0 @@ actual |
declare const getTypeSnapshot: (filename: string, snapshotName: string) => string | undefined; | ||
declare const updateTypeSnapshot: (filename: string, snapshotName: string, actualType: string) => void; | ||
declare const updateTypeSnapshot: (filename: string, snapshotName: string, actualType: null | string) => void; | ||
export { getTypeSnapshot, updateTypeSnapshot }; |
{ | ||
"name": "eslint-plugin-expect-type", | ||
"version": "0.5.0", | ||
"version": "0.5.1", | ||
"description": "ESLint plugin with ^? Twoslash, $ExpectError, and $ExpectType type assertions. π§©", | ||
@@ -5,0 +5,0 @@ "keywords": [ |
@@ -6,20 +6,13 @@ <h1 align="center">eslint-plugin-expect-type</h1> | ||
<p align="center"> | ||
<a href="#contributors" target="_blank"> | ||
<!-- prettier-ignore-start --> | ||
<!-- ALL-CONTRIBUTORS-BADGE:START - Do not remove or modify this section --> | ||
<img alt="All Contributors: 13 πͺ" src="https://img.shields.io/badge/all_contributors-13_πͺ-21bb42.svg" /> | ||
<a href="#contributors" target="_blank"><img alt="All Contributors: 13 πͺ" src="https://img.shields.io/badge/all_contributors-13_πͺ-21bb42.svg" /></a> | ||
<!-- ALL-CONTRIBUTORS-BADGE:END --> | ||
<!-- prettier-ignore-end --> | ||
</a> | ||
<a href="https://github.com/JoshuaKGoldberg/eslint-plugin-expect-type/blob/main/.github/CODE_OF_CONDUCT.md" target="_blank"> | ||
<img alt="Contributor Covenant" src="https://img.shields.io/badge/code_of_conduct-enforced-21bb42" /> | ||
</a> | ||
<a href="https://codecov.io/gh/JoshuaKGoldberg/eslint-plugin-expect-type" target="_blank"> | ||
<img alt="Codecov Test Coverage" src="https://codecov.io/gh/JoshuaKGoldberg/eslint-plugin-expect-type/branch/main/graph/badge.svg"/> | ||
</a> | ||
<a href="https://github.com/JoshuaKGoldberg/eslint-plugin-expect-type/blob/main/LICENSE.md" target="_blank"> | ||
<img alt="License: Apache-2.0" src="https://img.shields.io/github/license/JoshuaKGoldberg/eslint-plugin-expect-type?color=21bb42"> | ||
</a> | ||
<img alt="npm package version" src="https://img.shields.io/npm/v/eslint-plugin-expect-type?color=21bb42" /> | ||
<img alt="TypeScript: Strict" src="https://img.shields.io/badge/typescript-strict-21bb42.svg" /> | ||
<a href="https://github.com/JoshuaKGoldberg/eslint-plugin-expect-type/blob/main/.github/CODE_OF_CONDUCT.md" target="_blank"><img alt="Contributor Covenant" src="https://img.shields.io/badge/code_of_conduct-enforced-21bb42" /></a> | ||
<a href="https://codecov.io/gh/JoshuaKGoldberg/eslint-plugin-expect-type" target="_blank"><img alt="Codecov Test Coverage" src="https://codecov.io/gh/JoshuaKGoldberg/eslint-plugin-expect-type/branch/main/graph/badge.svg"/></a> | ||
<a href="https://github.com/JoshuaKGoldberg/eslint-plugin-expect-type/blob/main/LICENSE.md" target="_blank"><img alt="License: Apache-2.0" src="https://img.shields.io/github/license/JoshuaKGoldberg/eslint-plugin-expect-type?color=21bb42"></a> | ||
<img alt="npm package version" src="https://img.shields.io/npm/v/eslint-plugin-expect-type?color=21bb42" /> | ||
<img alt="TypeScript: Strict" src="https://img.shields.io/badge/typescript-strict-21bb42.svg" /> | ||
</p> | ||
@@ -26,0 +19,0 @@ |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
192441
2050
139