Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Linter] Add a linter rule to check if sdk-type exists in package.json #18565

Closed
wants to merge 4 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion common/tools/eslint-plugin-azure-sdk/src/configs/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,6 @@ export = {
"@azure/azure-sdk/ts-no-const-enums": "warn",
"@azure/azure-sdk/ts-no-namespaces": "error",
"@azure/azure-sdk/ts-no-window": "error",
"@azure/azure-sdk/ts-package-json-sdktype": "error",
"@azure/azure-sdk/ts-package-json-author": "error",
"@azure/azure-sdk/ts-package-json-bugs": "error",
"@azure/azure-sdk/ts-package-json-engine-is-present": "error",
Expand All @@ -61,6 +60,8 @@ export = {
"@azure/azure-sdk/ts-package-json-name": "error",
"@azure/azure-sdk/ts-package-json-repo": "error",
"@azure/azure-sdk/ts-package-json-required-scripts": "error",
"@azure/azure-sdk/ts-package-json-sdktype": "error",
"@azure/azure-sdk/ts-package-json-sdktype-exists": "error",
"@azure/azure-sdk/ts-package-json-sideeffects": "error",
"@azure/azure-sdk/ts-package-json-types": "error",
"@azure/azure-sdk/ts-pagination-list": "error",
Expand Down
4 changes: 3 additions & 1 deletion common/tools/eslint-plugin-azure-sdk/src/rules/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,6 @@ import tsNoConstEnums from "./ts-no-const-enums";
import tsNoNamespaces from "./ts-no-namespaces";
import tsNoWindow from "./ts-no-window";
import tsPackageJsonAuthor from "./ts-package-json-author";
import tsPackageJsonSdkType from "./ts-package-json-sdktype";
import tsPackageJsonBugs from "./ts-package-json-bugs";
import tsPackageJsonEngineIsPresent from "./ts-package-json-engine-is-present";
import tsPackageJsonFilesRequired from "./ts-package-json-files-required";
Expand All @@ -45,6 +44,8 @@ import tsPackageJsonModule from "./ts-package-json-module";
import tsPackageJsonName from "./ts-package-json-name";
import tsPackageJsonRepo from "./ts-package-json-repo";
import tsPackageJsonRequiredScripts from "./ts-package-json-required-scripts";
import tsPackageJsonSdkType from "./ts-package-json-sdktype";
import tsPackageJsonSdkTypeExists from "./ts-package-json-sdktype-exists";
import tsPackageJsonSideEffects from "./ts-package-json-sideeffects";
import tsPackageJsonTypes from "./ts-package-json-types";
import tsPaginationList from "./ts-pagination-list";
Expand Down Expand Up @@ -95,6 +96,7 @@ export = {
"ts-package-json-name": tsPackageJsonName,
"ts-package-json-repo": tsPackageJsonRepo,
"ts-package-json-required-scripts": tsPackageJsonRequiredScripts,
"ts-package-json-sdktype-exists": tsPackageJsonSdkTypeExists,
"ts-package-json-sideeffects": tsPackageJsonSideEffects,
"ts-package-json-types": tsPackageJsonTypes,
"ts-pagination-list": tsPaginationList,
Expand Down
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)
: {};
}
};
3 changes: 2 additions & 1 deletion common/tools/eslint-plugin-azure-sdk/tests/plugin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,6 @@ const ruleList = [
"ts-no-namespaces",
"ts-no-window",
"ts-package-json-author",
"ts-package-json-sdktype",
"ts-package-json-bugs",
"ts-package-json-engine-is-present",
"ts-package-json-files-required",
Expand All @@ -53,6 +52,8 @@ const ruleList = [
"ts-package-json-name",
"ts-package-json-repo",
"ts-package-json-required-scripts",
"ts-package-json-sdktype",
"ts-package-json-sdktype-exists",
"ts-package-json-sideeffects",
"ts-package-json-types",
"ts-pagination-list",
Expand Down
Loading