Skip to content
This repository has been archived by the owner on Oct 16, 2024. It is now read-only.

Commit

Permalink
Add error when type-checking is not enabled
Browse files Browse the repository at this point in the history
  • Loading branch information
stianjensen committed Sep 12, 2023
1 parent d579093 commit f23f426
Showing 1 changed file with 14 additions and 3 deletions.
17 changes: 14 additions & 3 deletions src/rules/deprecation.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,12 @@
* along with this program; if not, write to the Free Software Foundation,
* Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*/
import { ESLintUtils, TSESLint, TSESTree } from '@typescript-eslint/utils';
import {
ESLintUtils,
ParserServicesWithTypeInformation,
TSESLint,
TSESTree,
} from '@typescript-eslint/utils';
import { isReassignmentTarget } from 'tsutils';
import * as ts from 'typescript';
import { stringifyJSDocTagInfoText } from '../utils/stringifyJSDocTagInfoText';
Expand All @@ -32,7 +37,6 @@ export default createRule<Options, MessageIds>({
type: 'problem',
docs: {
description: 'Do not use deprecated APIs.',
recommended: 'warn',
requiresTypeChecking: true,
},
messages: {
Expand All @@ -42,6 +46,13 @@ export default createRule<Options, MessageIds>({
},
defaultOptions: [],
create(context) {
const services = ESLintUtils.getParserServices(context);
if (!services.program) {
throw new Error(
'TypeScript is required for this rule: https://github.com/gund/eslint-plugin-deprecation#prerequisites',
);
}

const identifierRule = createRuleForIdentifier(context);
return {
Identifier: identifierRule,
Expand Down Expand Up @@ -195,7 +206,7 @@ function isDeclaration(

function getDeprecation(
id: TSESTree.Identifier | TSESTree.JSXIdentifier,
services: RequiredParserServices,
services: ParserServicesWithTypeInformation,
context: TSESLint.RuleContext<MessageIds, Options>,
) {
const tc = services.program.getTypeChecker();
Expand Down

0 comments on commit f23f426

Please sign in to comment.