@prairielearn/eslint-plugin 1.0.8 → 2.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/CHANGELOG.md CHANGED
@@ -1,5 +1,17 @@
1
1
  # @prairielearn/eslint-plugin
2
2
 
3
+ ## 2.0.0
4
+
5
+ ### Major Changes
6
+
7
+ - 4f30b7e: Publish as native ESM
8
+
9
+ ## 1.0.9
10
+
11
+ ### Patch Changes
12
+
13
+ - c7e6553: Upgrade all JavaScript dependencies
14
+
3
15
  ## 1.0.8
4
16
 
5
17
  ### Patch Changes
package/dist/index.d.ts CHANGED
@@ -2,14 +2,12 @@ export declare const rules: {
2
2
  'aws-client-mandatory-config': {
3
3
  create(context: any): {
4
4
  ImportDeclaration(node: any): void;
5
- VariableDeclarator(node: any): void;
6
5
  NewExpression(node: any): void;
7
6
  };
8
7
  };
9
8
  'aws-client-shared-config': {
10
9
  create(context: any): {
11
10
  ImportDeclaration(node: any): void;
12
- VariableDeclarator(node: any): void;
13
11
  NewExpression(node: any): void;
14
12
  };
15
13
  };
package/dist/index.js CHANGED
@@ -1,13 +1,10 @@
1
1
  "use strict";
2
- var __importDefault = (this && this.__importDefault) || function (mod) {
3
- return (mod && mod.__esModule) ? mod : { "default": mod };
4
- };
5
2
  Object.defineProperty(exports, "__esModule", { value: true });
6
3
  exports.rules = void 0;
7
- const aws_client_mandatory_config_1 = __importDefault(require("./rules/aws-client-mandatory-config"));
8
- const aws_client_shared_config_1 = __importDefault(require("./rules/aws-client-shared-config"));
4
+ const aws_client_mandatory_config_js_1 = require("./rules/aws-client-mandatory-config.js");
5
+ const aws_client_shared_config_js_1 = require("./rules/aws-client-shared-config.js");
9
6
  exports.rules = {
10
- 'aws-client-mandatory-config': aws_client_mandatory_config_1.default,
11
- 'aws-client-shared-config': aws_client_shared_config_1.default,
7
+ 'aws-client-mandatory-config': aws_client_mandatory_config_js_1.default,
8
+ 'aws-client-shared-config': aws_client_shared_config_js_1.default,
12
9
  };
13
10
  //# sourceMappingURL=index.js.map
package/dist/index.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";;;;;;AAAA,sGAA2E;AAC3E,gGAAqE;AAExD,QAAA,KAAK,GAAG;IACnB,6BAA6B,EAAE,qCAAwB;IACvD,0BAA0B,EAAE,kCAAqB;CAClD,CAAC"}
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";;;AAAA,2FAA8E;AAC9E,qFAAwE;AAE3D,QAAA,KAAK,GAAG;IACnB,6BAA6B,EAAE,wCAAwB;IACvD,0BAA0B,EAAE,qCAAqB;CAClD,CAAC","sourcesContent":["import awsClientMandatoryConfig from './rules/aws-client-mandatory-config.js';\nimport awsClientSharedConfig from './rules/aws-client-shared-config.js';\n\nexport const rules = {\n 'aws-client-mandatory-config': awsClientMandatoryConfig,\n 'aws-client-shared-config': awsClientSharedConfig,\n};\n"]}
@@ -8,7 +8,6 @@
8
8
  declare const _default: {
9
9
  create(context: any): {
10
10
  ImportDeclaration(node: any): void;
11
- VariableDeclarator(node: any): void;
12
11
  NewExpression(node: any): void;
13
12
  };
14
13
  };
@@ -1,6 +1,6 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- const utils_1 = require("../utils");
3
+ const utils_js_1 = require("../utils.js");
4
4
  /**
5
5
  * This rule enforces that we always explicitly provide a config to AWS clients.
6
6
  * This helps ensure that we always construct a client with a specific region.
@@ -14,12 +14,7 @@ exports.default = {
14
14
  return {
15
15
  // Handle `import ...` statements
16
16
  ImportDeclaration(node) {
17
- const clientNames = (0, utils_1.getAwsClientNamesFromImportDeclaration)(node);
18
- clientNames.forEach((clientName) => awsClientImports.add(clientName));
19
- },
20
- // Handle `const ... = require(...)` statements
21
- VariableDeclarator(node) {
22
- const clientNames = (0, utils_1.getAwsClientNamesFromVariableDeclarator)(node);
17
+ const clientNames = (0, utils_js_1.getAwsClientNamesFromImportDeclaration)(node);
23
18
  clientNames.forEach((clientName) => awsClientImports.add(clientName));
24
19
  },
25
20
  NewExpression(node) {
@@ -1 +1 @@
1
- {"version":3,"file":"aws-client-mandatory-config.js","sourceRoot":"","sources":["../../src/rules/aws-client-mandatory-config.ts"],"names":[],"mappings":";;AAAA,oCAGkB;AAElB;;;;;;GAMG;AACH,kBAAe;IACb,MAAM,CAAC,OAAY;QACjB,MAAM,gBAAgB,GAAG,IAAI,GAAG,EAAE,CAAC;QAEnC,OAAO;YACL,iCAAiC;YACjC,iBAAiB,CAAC,IAAS;gBACzB,MAAM,WAAW,GAAG,IAAA,8CAAsC,EAAC,IAAI,CAAC,CAAC;gBACjE,WAAW,CAAC,OAAO,CAAC,CAAC,UAAU,EAAE,EAAE,CAAC,gBAAgB,CAAC,GAAG,CAAC,UAAU,CAAC,CAAC,CAAC;YACxE,CAAC;YACD,+CAA+C;YAC/C,kBAAkB,CAAC,IAAS;gBAC1B,MAAM,WAAW,GAAG,IAAA,+CAAuC,EAAC,IAAI,CAAC,CAAC;gBAClE,WAAW,CAAC,OAAO,CAAC,CAAC,UAAU,EAAE,EAAE,CAAC,gBAAgB,CAAC,GAAG,CAAC,UAAU,CAAC,CAAC,CAAC;YACxE,CAAC;YACD,aAAa,CAAC,IAAS;gBACrB,IAAI,IAAI,CAAC,MAAM,CAAC,IAAI,KAAK,YAAY,IAAI,gBAAgB,CAAC,GAAG,CAAC,IAAI,CAAC,MAAM,CAAC,IAAI,CAAC,EAAE,CAAC;oBAChF,gEAAgE;oBAChE,uDAAuD;oBACvD,IAAI,IAAI,CAAC,SAAS,CAAC,MAAM,KAAK,CAAC,EAAE,CAAC;wBAChC,OAAO,CAAC,MAAM,CAAC;4BACb,IAAI;4BACJ,OAAO,EAAE,GAAG,IAAI,CAAC,MAAM,CAAC,IAAI,4CAA4C;yBACzE,CAAC,CAAC;wBACH,OAAO;oBACT,CAAC;gBACH,CAAC;YACH,CAAC;SACF,CAAC;IACJ,CAAC;CACF,CAAC"}
1
+ {"version":3,"file":"aws-client-mandatory-config.js","sourceRoot":"","sources":["../../src/rules/aws-client-mandatory-config.ts"],"names":[],"mappings":";;AAAA,0CAAqE;AAErE;;;;;;GAMG;AACH,kBAAe;IACb,MAAM,CAAC,OAAY;QACjB,MAAM,gBAAgB,GAAG,IAAI,GAAG,EAAE,CAAC;QAEnC,OAAO;YACL,iCAAiC;YACjC,iBAAiB,CAAC,IAAS;gBACzB,MAAM,WAAW,GAAG,IAAA,iDAAsC,EAAC,IAAI,CAAC,CAAC;gBACjE,WAAW,CAAC,OAAO,CAAC,CAAC,UAAU,EAAE,EAAE,CAAC,gBAAgB,CAAC,GAAG,CAAC,UAAU,CAAC,CAAC,CAAC;YACxE,CAAC;YACD,aAAa,CAAC,IAAS;gBACrB,IAAI,IAAI,CAAC,MAAM,CAAC,IAAI,KAAK,YAAY,IAAI,gBAAgB,CAAC,GAAG,CAAC,IAAI,CAAC,MAAM,CAAC,IAAI,CAAC,EAAE,CAAC;oBAChF,gEAAgE;oBAChE,uDAAuD;oBACvD,IAAI,IAAI,CAAC,SAAS,CAAC,MAAM,KAAK,CAAC,EAAE,CAAC;wBAChC,OAAO,CAAC,MAAM,CAAC;4BACb,IAAI;4BACJ,OAAO,EAAE,GAAG,IAAI,CAAC,MAAM,CAAC,IAAI,4CAA4C;yBACzE,CAAC,CAAC;wBACH,OAAO;oBACT,CAAC;gBACH,CAAC;YACH,CAAC;SACF,CAAC;IACJ,CAAC;CACF,CAAC","sourcesContent":["import { getAwsClientNamesFromImportDeclaration } from '../utils.js';\n\n/**\n * This rule enforces that we always explicitly provide a config to AWS clients.\n * This helps ensure that we always construct a client with a specific region.\n *\n * This rules works in tandem with `aws-client-shared-config` to ensure that\n * we're properly configuring AWS SDK clients.\n */\nexport default {\n create(context: any) {\n const awsClientImports = new Set();\n\n return {\n // Handle `import ...` statements\n ImportDeclaration(node: any) {\n const clientNames = getAwsClientNamesFromImportDeclaration(node);\n clientNames.forEach((clientName) => awsClientImports.add(clientName));\n },\n NewExpression(node: any) {\n if (node.callee.type === 'Identifier' && awsClientImports.has(node.callee.name)) {\n // We're constructing an AWS client. Ensure that the call has at\n // least one argument corresponding to a config object.\n if (node.arguments.length === 0) {\n context.report({\n node,\n message: `${node.callee.name} must be constructed with a config object.`,\n });\n return;\n }\n }\n },\n };\n },\n};\n"]}
@@ -19,7 +19,6 @@
19
19
  declare const _default: {
20
20
  create(context: any): {
21
21
  ImportDeclaration(node: any): void;
22
- VariableDeclarator(node: any): void;
23
22
  NewExpression(node: any): void;
24
23
  };
25
24
  };
@@ -1,6 +1,6 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- const utils_1 = require("../utils");
3
+ const utils_js_1 = require("../utils.js");
4
4
  /**
5
5
  * This ESLint rules enforces that we always provide a "shared" config to AWS
6
6
  * clients.
@@ -25,12 +25,7 @@ exports.default = {
25
25
  return {
26
26
  // Handle `import ...` statements
27
27
  ImportDeclaration(node) {
28
- const clientNames = (0, utils_1.getAwsClientNamesFromImportDeclaration)(node);
29
- clientNames.forEach((clientName) => awsClientImports.add(clientName));
30
- },
31
- // Handle `const ... = require(...)` statements
32
- VariableDeclarator(node) {
33
- const clientNames = (0, utils_1.getAwsClientNamesFromVariableDeclarator)(node);
28
+ const clientNames = (0, utils_js_1.getAwsClientNamesFromImportDeclaration)(node);
34
29
  clientNames.forEach((clientName) => awsClientImports.add(clientName));
35
30
  },
36
31
  NewExpression(node) {
@@ -1 +1 @@
1
- {"version":3,"file":"aws-client-shared-config.js","sourceRoot":"","sources":["../../src/rules/aws-client-shared-config.ts"],"names":[],"mappings":";;AAAA,oCAGkB;AAElB;;;;;;;;;;;;;;;;;GAiBG;AACH,kBAAe;IACb,MAAM,CAAC,OAAY;QACjB,MAAM,gBAAgB,GAAG,IAAI,GAAG,EAAU,CAAC;QAE3C,OAAO;YACL,iCAAiC;YACjC,iBAAiB,CAAC,IAAS;gB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;oBACT,CAAC;oBAED,uCAAuC;oBACvC,IAAI,cAAc,CAAC,MAAM,CAAC,IAAI,KAAK,kBAAkB,EAAE,CAAC;wBACtD,MAAM,YAAY,GAAG,cAAc,CAAC,MAAM,CAAC,QAAQ,CAAC,IAAI,CAAC;wBACzD,IAAI,YAAY,KAAK,yBAAyB,EAAE,CAAC;4BAC/C,OAAO,CAAC,MAAM,CAAC;gCACb,IAAI;gCACJ,OAAO,EAAE,cAAc,IAAI,CAAC,MAAM,CAAC,IAAI,gCAAgC,yBAAyB,KAAK;6BACtG,CAAC,CAAC;wBACL,CAAC;wBACD,OAAO;oBACT,CAAC;oBAED,IAAI,cAAc,CAAC,MAAM,CAAC,IAAI,KAAK,YAAY,EAAE,CAAC;wBAChD,MAAM,YAAY,GAAG,cAAc,CAAC,MAAM,CAAC,IAAI,CAAC;wBAChD,IAAI,YAAY,KAAK,yBAAyB,EAAE,CAAC;4BAC/C,OAAO,CAAC,MAAM,CAAC;gCACb,IAAI;gCACJ,OAAO,EAAE,cAAc,IAAI,CAAC,MAAM,CAAC,IAAI,gCAAgC,yBAAyB,KAAK;6BACtG,CAAC,CAAC;wBACL,CAAC;wBACD,OAAO;oBACT,CAAC;oBAED,OAAO,CAAC,MAAM,CAAC;wBACb,IAAI;wBACJ,OAAO,EAAE,wCAAwC;qBAClD,CAAC,CAAC;gBACL,CAAC;YACH,CAAC;SACF,CAAC;IACJ,CAAC;CACF,CAAC"}
1
+ {"version":3,"file":"aws-client-shared-config.js","sourceRoot":"","sources":["../../src/rules/aws-client-shared-config.ts"],"names":[],"mappings":";;AAAA,0CAAqE;AAErE;;;;;;;;;;;;;;;;;GAiBG;AACH,kBAAe;IACb,MAAM,CAAC,OAAY;QACjB,MAAM,gBAAgB,GAAG,IAAI,GAAG,EAAU,CAAC;QAE3C,OAAO;YACL,iCAAiC;YACjC,iBAAiB,CAAC,IAAS;gBACzB,MAAM,WAAW,GAAG,IAAA,iDAAsC,EAAC,IAAI,CAAC,CAAC;g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,CAAC,MAAM,CAAC,IAAI,gCAAgC,yBAAyB,KAAK;6BACtG,CAAC,CAAC;wBACL,CAAC;wBACD,OAAO;oBACT,CAAC;oBAED,IAAI,cAAc,CAAC,MAAM,CAAC,IAAI,KAAK,YAAY,EAAE,CAAC;wBAChD,MAAM,YAAY,GAAG,cAAc,CAAC,MAAM,CAAC,IAAI,CAAC;wBAChD,IAAI,YAAY,KAAK,yBAAyB,EAAE,CAAC;4BAC/C,OAAO,CAAC,MAAM,CAAC;gCACb,IAAI;gCACJ,OAAO,EAAE,cAAc,IAAI,CAAC,MAAM,CAAC,IAAI,gCAAgC,yBAAyB,KAAK;6BACtG,CAAC,CAAC;wBACL,CAAC;wBACD,OAAO;oBACT,CAAC;oBAED,OAAO,CAAC,MAAM,CAAC;wBACb,IAAI;wBACJ,OAAO,EAAE,wCAAwC;qBAClD,CAAC,CAAC;gBACL,CAAC;YACH,CAAC;SACF,CAAC;IACJ,CAAC;CACF,CAAC","sourcesContent":["import { getAwsClientNamesFromImportDeclaration } from '../utils.js';\n\n/**\n * This ESLint rules enforces that we always provide a \"shared\" config to AWS\n * clients.\n *\n * This rule is extremely opinionated: it checks that the first argument to an\n * AWS client constructor consists of a function call to a function named\n * `makeAwsClientConfig()` (or `makeS3ClientConfig()` for S3 clients). This\n * is our convention to ensure that all clients will reuse credential providers,\n * which is important for ensuring that we don't overload IMDS with requests\n * for credentials if we construct a lot of clients in rapid succession.\n *\n * This is perhaps less than ideal, but the risk of misconfiguring a client is\n * high enough that we err towards being extremely prescriptive about how we\n * configure them.\n *\n * This rules works in tandem with `aws-client-mandatory-config` to ensure that\n * we're properly configuring AWS SDK clients.\n */\nexport default {\n create(context: any) {\n const awsClientImports = new Set<string>();\n\n return {\n // Handle `import ...` statements\n ImportDeclaration(node: any) {\n const clientNames = getAwsClientNamesFromImportDeclaration(node);\n clientNames.forEach((clientName) => awsClientImports.add(clientName));\n },\n NewExpression(node: any) {\n if (node.callee.type === 'Identifier' && awsClientImports.has(node.callee.name)) {\n // We're constructing an AWS client. Ensure that the first argument\n // comes from one of our config providers.\n\n if (node.arguments.length === 0) {\n // There is no argument to check. If the `aws-client-mandatory-config`\n // rule is enabled, it will catch this case.\n return;\n }\n\n let desiredConfigFunctionName = 'makeAwsClientConfig';\n\n // Special-case: S3 client.\n if (node.callee.name === 'S3Client' || node.callee.name === 'S3') {\n desiredConfigFunctionName = 'makeS3ClientConfig';\n }\n\n const configArgument = node.arguments[0];\n if (configArgument.type !== 'CallExpression') {\n context.report({\n node,\n message: `Config for ${node.callee.name} must be obtained by calling ${desiredConfigFunctionName}().`,\n });\n return;\n }\n\n // Handle member calls to the function.\n if (configArgument.callee.type === 'MemberExpression') {\n const functionName = configArgument.callee.property.name;\n if (functionName !== desiredConfigFunctionName) {\n context.report({\n node,\n message: `Config for ${node.callee.name} must be obtained by calling ${desiredConfigFunctionName}().`,\n });\n }\n return;\n }\n\n if (configArgument.callee.type === 'Identifier') {\n const functionName = configArgument.callee.name;\n if (functionName !== desiredConfigFunctionName) {\n context.report({\n node,\n message: `Config for ${node.callee.name} must be obtained by calling ${desiredConfigFunctionName}().`,\n });\n }\n return;\n }\n\n context.report({\n node,\n message: `Unknown config provided to AWS client.`,\n });\n }\n },\n };\n },\n};\n"]}
package/dist/utils.d.ts CHANGED
@@ -15,16 +15,3 @@ export declare function isIdentifierClient(identifierName: string, packageName:
15
15
  * then this function will return a set containing the strings "S3" and "S3Client".
16
16
  */
17
17
  export declare function getAwsClientNamesFromImportDeclaration(node: any): Set<string>;
18
- /**
19
- * Retrieves the names of AWS client specified by the given variable declarator.
20
- * This is used to handle CJS require statements.
21
- *
22
- * For instance, if the variable declarator is:
23
- *
24
- * ```ts
25
- * const { S3, S3Client } = require('@aws-sdk/client-s3');
26
- * ```
27
- *
28
- * then this function will return a set containing the strings "S3" and "S3Client".
29
- */
30
- export declare function getAwsClientNamesFromVariableDeclarator(node: any): Set<string>;
package/dist/utils.js CHANGED
@@ -1,6 +1,6 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.getAwsClientNamesFromVariableDeclarator = exports.getAwsClientNamesFromImportDeclaration = exports.isIdentifierClient = void 0;
3
+ exports.getAwsClientNamesFromImportDeclaration = exports.isIdentifierClient = void 0;
4
4
  /**
5
5
  * Determines if the given identifier name corresponds to a client from the
6
6
  * given package.
@@ -46,38 +46,4 @@ function getAwsClientNamesFromImportDeclaration(node) {
46
46
  return clientNames;
47
47
  }
48
48
  exports.getAwsClientNamesFromImportDeclaration = getAwsClientNamesFromImportDeclaration;
49
- /**
50
- * Retrieves the names of AWS client specified by the given variable declarator.
51
- * This is used to handle CJS require statements.
52
- *
53
- * For instance, if the variable declarator is:
54
- *
55
- * ```ts
56
- * const { S3, S3Client } = require('@aws-sdk/client-s3');
57
- * ```
58
- *
59
- * then this function will return a set containing the strings "S3" and "S3Client".
60
- */
61
- function getAwsClientNamesFromVariableDeclarator(node) {
62
- const clientNames = new Set();
63
- if (node.init &&
64
- node.init.type === 'CallExpression' &&
65
- node.init.callee.name === 'require' &&
66
- node.init.arguments.length === 1 &&
67
- node.init.arguments[0].type === 'Literal' &&
68
- typeof node.init.arguments[0].value === 'string' &&
69
- node.init.arguments[0].value.startsWith('@aws-sdk/client-')) {
70
- if (node.id.type !== 'ObjectPattern') {
71
- throw new Error('Unexpected node type');
72
- }
73
- node.id.properties.forEach((property) => {
74
- const specifierName = property.key.name;
75
- if (isIdentifierClient(specifierName, node.init.arguments[0].value)) {
76
- clientNames.add(property.value.name);
77
- }
78
- });
79
- }
80
- return clientNames;
81
- }
82
- exports.getAwsClientNamesFromVariableDeclarator = getAwsClientNamesFromVariableDeclarator;
83
49
  //# sourceMappingURL=utils.js.map
package/dist/utils.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"utils.js","sourceRoot":"","sources":["../src/utils.ts"],"names":[],"mappings":";;;AAAA;;;GAGG;AACH,SAAgB,kBAAkB,CAAC,cAAsB,EAAE,WAAmB;IAC5E,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ED,8EAA8E;IAC9E,MAAM,UAAU,GAAG,WAAW,CAAC,OAAO,CAAC,kBAAkB,EAAE,EAAE,CAAC,CAAC;IAC/D,MAAM,iBAAiB,GAAG,UAAU,CAAC,OAAO,CAAC,IAAI,EAAE,EAAE,CAAC,CAAC,WAAW,EAAE,CAAC;IACrE,IAAI,cAAc,CAAC,WAAW,EAAE,KAAK,iBAAiB,EAAE,CAAC;QACvD,OAAO,IAAI,CAAC;IACd,CAAC;IAED,OAAO,KAAK,CAAC;AACf,CAAC;AAdD,gDAcC;AAED;;;;;;;;;;GAUG;AACH,SAAgB,sCAAsC,CAAC,IAAS;IAC9D,MAAM,WAAW,GAAG,IAAI,GAAG,EAAU,CAAC;IAEtC,MAAM,YAAY,GAAG,IAAI,CAAC,MAAM,CAAC,KAAK,CAAC;IACvC,IAAI,YAAY,CAAC,UAAU,CAAC,kBAAkB,CAAC,EAAE,CAAC;QAChD,IAAI,CAAC,UAAU,CAAC,OAAO,CAAC,CAAC,SAAc,EAAE,EAAE;YACzC,IAAI,SAAS,CAAC,IAAI,KAAK,iBAAiB,EAAE,CAAC;gBACzC,MAAM,aAAa,GAAG,SAAS,CAAC,QAAQ,CAAC,IAAI,CAAC;gBAC9C,IAAI,kBAAkB,CAAC,aAAa,EAAE,YAAY,CAAC,EAAE,CAAC;oBACpD,WAAW,CAAC,GAAG,CAAC,aAAa,CAAC,CAAC;gBACjC,CAAC;YACH,CAAC;QACH,CAAC,CAAC,CAAC;IACL,CAAC;IAED,OAAO,WAAW,CAAC;AACrB,CAAC;AAhBD,wFAgBC","sourcesContent":["/**\n * Determines if the given identifier name corresponds to a client from the\n * given package.\n */\nexport function isIdentifierClient(identifierName: string, packageName: string): boolean {\n // If the identifier ends with \"Client\", include it in the set.\n if (identifierName.endsWith('Client')) {\n return true;\n }\n\n // If the identifier matches the package name directly, include it in the set.\n const clientName = packageName.replace('@aws-sdk/client-', '');\n const packageIdentifier = clientName.replace(/-/g, '').toLowerCase();\n if (identifierName.toLowerCase() === packageIdentifier) {\n return true;\n }\n\n return false;\n}\n\n/**\n * Retrieves the names of AWS clients specified by the given import declaration.\n *\n * For instance, if the import declaration is:\n *\n * ```ts\n * import { S3, S3Client } from '@aws-sdk/client-s3';\n * ```\n *\n * then this function will return a set containing the strings \"S3\" and \"S3Client\".\n */\nexport function getAwsClientNamesFromImportDeclaration(node: any) {\n const clientNames = new Set<string>();\n\n const importSource = node.source.value;\n if (importSource.startsWith('@aws-sdk/client-')) {\n node.specifiers.forEach((specifier: any) => {\n if (specifier.type === 'ImportSpecifier') {\n const specifierName = specifier.imported.name;\n if (isIdentifierClient(specifierName, importSource)) {\n clientNames.add(specifierName);\n }\n }\n });\n }\n\n return clientNames;\n}\n"]}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@prairielearn/eslint-plugin",
3
- "version": "1.0.8",
3
+ "version": "2.0.0",
4
4
  "main": "./dist/index.js",
5
5
  "repository": {
6
6
  "type": "git",
@@ -13,7 +13,7 @@
13
13
  },
14
14
  "devDependencies": {
15
15
  "@prairielearn/tsconfig": "^0.0.0",
16
- "@types/node": "^20.11.30",
16
+ "@types/node": "^20.12.2",
17
17
  "typescript": "^5.4.3"
18
18
  }
19
19
  }
package/src/index.ts CHANGED
@@ -1,5 +1,5 @@
1
- import awsClientMandatoryConfig from './rules/aws-client-mandatory-config';
2
- import awsClientSharedConfig from './rules/aws-client-shared-config';
1
+ import awsClientMandatoryConfig from './rules/aws-client-mandatory-config.js';
2
+ import awsClientSharedConfig from './rules/aws-client-shared-config.js';
3
3
 
4
4
  export const rules = {
5
5
  'aws-client-mandatory-config': awsClientMandatoryConfig,
@@ -1,7 +1,4 @@
1
- import {
2
- getAwsClientNamesFromImportDeclaration,
3
- getAwsClientNamesFromVariableDeclarator,
4
- } from '../utils';
1
+ import { getAwsClientNamesFromImportDeclaration } from '../utils.js';
5
2
 
6
3
  /**
7
4
  * This rule enforces that we always explicitly provide a config to AWS clients.
@@ -20,11 +17,6 @@ export default {
20
17
  const clientNames = getAwsClientNamesFromImportDeclaration(node);
21
18
  clientNames.forEach((clientName) => awsClientImports.add(clientName));
22
19
  },
23
- // Handle `const ... = require(...)` statements
24
- VariableDeclarator(node: any) {
25
- const clientNames = getAwsClientNamesFromVariableDeclarator(node);
26
- clientNames.forEach((clientName) => awsClientImports.add(clientName));
27
- },
28
20
  NewExpression(node: any) {
29
21
  if (node.callee.type === 'Identifier' && awsClientImports.has(node.callee.name)) {
30
22
  // We're constructing an AWS client. Ensure that the call has at
@@ -1,7 +1,4 @@
1
- import {
2
- getAwsClientNamesFromImportDeclaration,
3
- getAwsClientNamesFromVariableDeclarator,
4
- } from '../utils';
1
+ import { getAwsClientNamesFromImportDeclaration } from '../utils.js';
5
2
 
6
3
  /**
7
4
  * This ESLint rules enforces that we always provide a "shared" config to AWS
@@ -31,11 +28,6 @@ export default {
31
28
  const clientNames = getAwsClientNamesFromImportDeclaration(node);
32
29
  clientNames.forEach((clientName) => awsClientImports.add(clientName));
33
30
  },
34
- // Handle `const ... = require(...)` statements
35
- VariableDeclarator(node: any) {
36
- const clientNames = getAwsClientNamesFromVariableDeclarator(node);
37
- clientNames.forEach((clientName) => awsClientImports.add(clientName));
38
- },
39
31
  NewExpression(node: any) {
40
32
  if (node.callee.type === 'Identifier' && awsClientImports.has(node.callee.name)) {
41
33
  // We're constructing an AWS client. Ensure that the first argument
package/src/utils.ts CHANGED
@@ -46,42 +46,3 @@ export function getAwsClientNamesFromImportDeclaration(node: any) {
46
46
 
47
47
  return clientNames;
48
48
  }
49
-
50
- /**
51
- * Retrieves the names of AWS client specified by the given variable declarator.
52
- * This is used to handle CJS require statements.
53
- *
54
- * For instance, if the variable declarator is:
55
- *
56
- * ```ts
57
- * const { S3, S3Client } = require('@aws-sdk/client-s3');
58
- * ```
59
- *
60
- * then this function will return a set containing the strings "S3" and "S3Client".
61
- */
62
- export function getAwsClientNamesFromVariableDeclarator(node: any) {
63
- const clientNames = new Set<string>();
64
-
65
- if (
66
- node.init &&
67
- node.init.type === 'CallExpression' &&
68
- node.init.callee.name === 'require' &&
69
- node.init.arguments.length === 1 &&
70
- node.init.arguments[0].type === 'Literal' &&
71
- typeof node.init.arguments[0].value === 'string' &&
72
- node.init.arguments[0].value.startsWith('@aws-sdk/client-')
73
- ) {
74
- if (node.id.type !== 'ObjectPattern') {
75
- throw new Error('Unexpected node type');
76
- }
77
-
78
- node.id.properties.forEach((property: any) => {
79
- const specifierName = property.key.name;
80
- if (isIdentifierClient(specifierName, node.init.arguments[0].value)) {
81
- clientNames.add(property.value.name);
82
- }
83
- });
84
- }
85
-
86
- return clientNames;
87
- }
package/tsconfig.json CHANGED
@@ -1,5 +1,6 @@
1
1
  {
2
- "extends": "@prairielearn/tsconfig/tsconfig.package.json",
2
+ // This must be a CJS package because ESLint doesn't support ESM plugins.
3
+ "extends": "@prairielearn/tsconfig/tsconfig.package-cjs.json",
3
4
  "compilerOptions": {
4
5
  "outDir": "./dist",
5
6
  "rootDir": "./src",