Skip to content

Commit bf15b3a

Browse files
authored
chore: move to eslint and prettier (aws#309)
Typescript is moving to eslint and prettier is now the standard. This first PR updates all source files with these new linting/formatting rules. The test are NOT changed. This is to help the reviews confirm that all changes are format only.
1 parent dab43a0 commit bf15b3a

File tree

171 files changed

+6668
-3408
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

171 files changed

+6668
-3408
lines changed

Diff for: .eslintrc.js

+90
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,90 @@
1+
// Copyright Amazon.com Inc. or its affiliates. All Rights Reserved.
2+
// SPDX-License-Identifier: Apache-2.0
3+
4+
/*
5+
If you are here to disable rules
6+
to try and fix specific rule sets
7+
use
8+
npm install --no-save eslint-nibble
9+
*/
10+
11+
module.exports = {
12+
root: true,
13+
parser: '@typescript-eslint/parser',
14+
parserOptions: {
15+
// There is an issue with @typescript-eslint/parser performance.
16+
// It scales with the number of projects
17+
// see https://github.com/typescript-eslint/typescript-eslint/issues/1192#issuecomment-596741806
18+
project: './tsconfig.lint.json',
19+
tsconfigRootDir: process.cwd(),
20+
},
21+
plugins: ['@typescript-eslint'],
22+
extends: [
23+
'eslint:recommended',
24+
'plugin:@typescript-eslint/eslint-recommended',
25+
'plugin:@typescript-eslint/recommended',
26+
'prettier',
27+
],
28+
ignorePatterns: ['node_modules/'],
29+
rules: {
30+
// These are the most useful linting rules.
31+
// They rely on types so they are the slowest rules,
32+
// and they are NOT enabled by default on any
33+
// shared plugins that I know of.
34+
'@typescript-eslint/no-floating-promises': 'error',
35+
'@typescript-eslint/promise-function-async': 'error',
36+
'@typescript-eslint/no-misused-promises': 'error',
37+
// I disagree with these rules.
38+
// Humans read from less specific to more specific.
39+
// No on puts the outline at the end of the book.
40+
// Since the exported functions should be composed
41+
// of lower level functions,
42+
// it is good for understanding
43+
// for the source files to get more detailed
44+
// as you read down from the top.
45+
'no-use-before-define': ['error', { functions: false }],
46+
'@typescript-eslint/no-use-before-define': ['error', { functions: false }],
47+
// This is used in a few specific ways.
48+
// It may be that adding this to overrides for the tests
49+
// and then manual line overrides would be
50+
// the best way to handle this later.
51+
'@typescript-eslint/no-explicit-any': 'off',
52+
// Minimize churn.
53+
'@typescript-eslint/member-delimiter-style': [
54+
'error',
55+
{
56+
multiline: {
57+
delimiter: 'none',
58+
requireLast: false,
59+
},
60+
singleline: {
61+
delimiter: 'semi',
62+
requireLast: false,
63+
},
64+
},
65+
],
66+
// The ESDK exports some interfaces
67+
// that conflict with this rule.
68+
// At a later date, this might be
69+
// able to be turned on,
70+
// but to ensure ZERO interface changes
71+
// this rule is disabled.
72+
// To be clear this would only impact
73+
// Typescript use of some types/interfaces.
74+
'@typescript-eslint/no-empty-interface': 'off',
75+
// To minimize the source change,
76+
// this is turned of.
77+
'@typescript-eslint/ban-ts-ignore': 'off',
78+
},
79+
// This is a good rule,
80+
// but in many tests,
81+
// we are just looking to mock specific functions.
82+
overrides: [
83+
{
84+
files: ['modules/**/test/**/*.ts'],
85+
rules: {
86+
'@typescript-eslint/no-empty-function': 'off',
87+
},
88+
},
89+
],
90+
}

Diff for: .prettierrc.js

+9
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
// Copyright Amazon.com Inc. or its affiliates. All Rights Reserved.
2+
// SPDX-License-Identifier: Apache-2.0
3+
4+
// I would prefer to use the default configuration
5+
// but then the diff is out of control.
6+
module.exports = {
7+
semi: false,
8+
singleQuote: true
9+
}

Diff for: modules/cache-material/.eslintrc.js

+12
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
// Copyright Amazon.com Inc. or its affiliates. All Rights Reserved.
2+
// SPDX-License-Identifier: Apache-2.0
3+
4+
module.exports = {
5+
parserOptions: {
6+
// There is an issue with @typescript-eslint/parser performance.
7+
// It scales with the number of projects
8+
// see https://github.com/typescript-eslint/typescript-eslint/issues/1192#issuecomment-596741806
9+
project: '../../tsconfig.lint.json',
10+
tsconfigRootDir: __dirname,
11+
}
12+
}

Diff for: modules/cache-material/package.json

+4-8
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,9 @@
44
"scripts": {
55
"prepublishOnly": "npm run build",
66
"build": "tsc -b tsconfig.json && tsc -b tsconfig.module.json",
7-
"lint": "standard src/*.ts test/**/*.ts",
7+
"lint": "run-s lint-*",
8+
"lint-eslint": "eslint src/*.ts test/**/*.ts",
9+
"lint-prettier": "prettier -c src/*.ts test/**/*.ts",
810
"mocha": "mocha --require ts-node/register test/**/*test.ts",
911
"test": "npm run lint && npm run coverage",
1012
"coverage": "nyc -e .ts npm run mocha"
@@ -28,11 +30,5 @@
2830
"types": "./build/main/index.d.ts",
2931
"files": [
3032
"build/**/*"
31-
],
32-
"standard": {
33-
"parser": "@typescript-eslint/parser",
34-
"plugins": [
35-
"@typescript-eslint"
36-
]
37-
}
33+
]
3834
}

Diff for: modules/cache-material/src/build_cryptographic_materials_cache_key_helpers.ts

+24-16
Original file line numberDiff line numberDiff line change
@@ -2,36 +2,38 @@
22
// SPDX-License-Identifier: Apache-2.0
33

44
import {
5-
SupportedAlgorithmSuites, // eslint-disable-line no-unused-vars
6-
DecryptionRequest, // eslint-disable-line no-unused-vars
7-
EncryptionRequest, // eslint-disable-line no-unused-vars
8-
EncryptedDataKey, // eslint-disable-line no-unused-vars
9-
EncryptionContext // eslint-disable-line no-unused-vars
5+
SupportedAlgorithmSuites,
6+
DecryptionRequest,
7+
EncryptionRequest,
8+
EncryptedDataKey,
9+
EncryptionContext,
1010
} from '@aws-crypto/material-management'
1111
import { serializeFactory, uInt16BE } from '@aws-crypto/serialize'
1212
import { compare } from './portable_compare'
1313

1414
// 512 bits of 0 for padding between hashes in decryption materials cache ID generation.
1515
const BIT_PAD_512 = Buffer.alloc(64)
1616

17-
export function buildCryptographicMaterialsCacheKeyHelpers<S extends SupportedAlgorithmSuites> (
17+
export function buildCryptographicMaterialsCacheKeyHelpers<
18+
S extends SupportedAlgorithmSuites
19+
>(
1820
fromUtf8: (input: string) => Uint8Array,
1921
toUtf8: (input: Uint8Array) => string,
20-
sha512: (...data: ((Uint8Array|string))[]) => Promise<Uint8Array>
22+
sha512: (...data: (Uint8Array | string)[]) => Promise<Uint8Array>
2123
): CryptographicMaterialsCacheKeyHelpersInterface<S> {
2224
const {
2325
serializeEncryptionContext,
24-
serializeEncryptedDataKey
26+
serializeEncryptedDataKey,
2527
} = serializeFactory(fromUtf8)
2628

2729
return {
2830
buildEncryptionMaterialCacheKey,
2931
buildDecryptionMaterialCacheKey,
3032
encryptedDataKeysHash,
31-
encryptionContextHash
33+
encryptionContextHash,
3234
}
3335

34-
async function buildEncryptionMaterialCacheKey (
36+
async function buildEncryptionMaterialCacheKey(
3537
partition: string,
3638
{ suite, encryptionContext }: EncryptionRequest<S>
3739
) {
@@ -47,7 +49,7 @@ export function buildCryptographicMaterialsCacheKeyHelpers<S extends SupportedAl
4749
return toUtf8(key)
4850
}
4951

50-
async function buildDecryptionMaterialCacheKey (
52+
async function buildDecryptionMaterialCacheKey(
5153
partition: string,
5254
{ suite, encryptedDataKeys, encryptionContext }: DecryptionRequest<S>
5355
) {
@@ -63,16 +65,18 @@ export function buildCryptographicMaterialsCacheKeyHelpers<S extends SupportedAl
6365
return toUtf8(key)
6466
}
6567

66-
async function encryptedDataKeysHash (encryptedDataKeys: ReadonlyArray<EncryptedDataKey>) {
68+
async function encryptedDataKeysHash(
69+
encryptedDataKeys: ReadonlyArray<EncryptedDataKey>
70+
) {
6771
const hashes = await Promise.all(
6872
encryptedDataKeys
6973
.map(serializeEncryptedDataKey)
70-
.map(edk => sha512(edk))
74+
.map(async (edk) => sha512(edk))
7175
)
7276
return hashes.sort(compare)
7377
}
7478

75-
function encryptionContextHash (context: EncryptionContext) {
79+
async function encryptionContextHash(context: EncryptionContext) {
7680
/* The AAD section is uInt16BE(length) + AAD
7781
* see: https://docs.aws.amazon.com/encryption-sdk/latest/developer-guide/message-format.html#header-aad
7882
* However, the RAW Keyring wants _only_ the ADD.
@@ -83,7 +87,9 @@ export function buildCryptographicMaterialsCacheKeyHelpers<S extends SupportedAl
8387
}
8488
}
8589

86-
export interface CryptographicMaterialsCacheKeyHelpersInterface<S extends SupportedAlgorithmSuites> {
90+
export interface CryptographicMaterialsCacheKeyHelpersInterface<
91+
S extends SupportedAlgorithmSuites
92+
> {
8793
buildEncryptionMaterialCacheKey(
8894
partition: string,
8995
{ suite, encryptionContext }: EncryptionRequest<S>
@@ -92,6 +98,8 @@ export interface CryptographicMaterialsCacheKeyHelpersInterface<S extends Suppor
9298
partition: string,
9399
{ suite, encryptedDataKeys, encryptionContext }: DecryptionRequest<S>
94100
): Promise<string>
95-
encryptedDataKeysHash(encryptedDataKeys: ReadonlyArray<EncryptedDataKey>): Promise<Uint8Array[]>
101+
encryptedDataKeysHash(
102+
encryptedDataKeys: ReadonlyArray<EncryptedDataKey>
103+
): Promise<Uint8Array[]>
96104
encryptionContextHash(context: EncryptionContext): Promise<Uint8Array>
97105
}

0 commit comments

Comments
 (0)