-
Notifications
You must be signed in to change notification settings - Fork 1.2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
add a linter rule to check if exists in package.json
- Loading branch information
Showing
1 changed file
with
35 additions
and
0 deletions.
There are no files selected for viewing
35 changes: 35 additions & 0 deletions
35
common/tools/eslint-plugin-azure-sdk/src/rules/ts-package-json-sdktype-exists.ts
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,35 @@ | ||
// Copyright (c) Microsoft Corporation. | ||
// Licensed under the MIT license. | ||
|
||
/** | ||
* @file Rule to check if package.json includes 'sdk-type' | ||
* @author Ben Zhang | ||
*/ | ||
|
||
import { Rule } from "eslint"; | ||
import { getRuleMetaData, getVerifiers, stripPath } from "../utils"; | ||
|
||
//------------------------------------------------------------------------------ | ||
// Rule Definition | ||
//------------------------------------------------------------------------------ | ||
|
||
export = { | ||
meta: getRuleMetaData( | ||
"ts-package-json-sdktype-exists", | ||
"check if package.json includes 'sdk-type'", | ||
"code" | ||
), | ||
create: (context: Rule.RuleContext): Rule.RuleListener => { | ||
const verifiers = getVerifiers(context, { | ||
outer: "sdk-type", | ||
}); | ||
return stripPath(context.getFilename()) === "package.json" | ||
? ({ | ||
// callback functions | ||
|
||
// check to see if package.json includes 'sdk-type' | ||
"ExpressionStatement > ObjectExpression": verifiers.existsInFile, | ||
} as Rule.RuleListener) | ||
: {}; | ||
} | ||
}; |