Skip to content

Commit 56a7b47

Browse files
authored
chore(all): removed unused npm scripts + moved linting in PR checks (#1125)
* chore: removed unused npm scripts + moved linting in PR checks * fix: typo in npm command * chore: added @typescript-eslint/eslint-plugin to examples * chore: added eslint dependencies to examples * fix: add eslint local config to examples * fix: added eslintrc to cdk * fix: added scoped linting to layer-publisher * chore: update husky to lint everything * chore: update GH CodeSpaces & GitPod specs * chore: update GH CodeSpaces & GitPod specs * fix: cache key in layer-publisher * fix: add local eslintrc to layer-publisher * chore: remove lerna mention in contributing
1 parent 8b85db1 commit 56a7b47

27 files changed

+9314
-341
lines changed

Diff for: .devcontainer/devcontainer.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@
2626
"ms-azuretools.vscode-docker"
2727
],
2828
// Use 'postCreateCommand' to run commands after the container is created.
29-
"postCreateCommand": "npm ci --foreground-scripts; cd examples/cdk; npm ci; cd ../sam; npm ci; cd ../../; npm run init-environment",
29+
"postCreateCommand": "npm run setup-local",
3030
// Comment out connect as root instead. More info: https://aka.ms/vscode-remote/containers/non-root.
3131
"remoteUser": "node"
3232
}

Diff for: .github/workflows/pr_lint_and_test.yml renamed to .github/workflows/pr-run-linting-check-and-unit-tests.yml

+1-1
Original file line numberDiff line numberDiff line change
@@ -5,4 +5,4 @@ on:
55
types: [opened, synchronize]
66
jobs:
77
run-unit-tests:
8-
uses: ./.github/workflows/reusable-run-unit-tests.yml
8+
uses: ./.github/workflows/reusable-run-linting-check-and-unit-tests.yml

Diff for: .github/workflows/reusable-run-unit-tests.yml renamed to .github/workflows/reusable-run-linting-check-and-unit-tests.yml

+14-8
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ on:
44
workflow_call:
55

66
jobs:
7-
run-unit-tests-on-utils:
7+
run-linting-check-and-unit-tests-on-utilities:
88
runs-on: ubuntu-latest
99
env:
1010
NODE_ENV: dev
@@ -29,21 +29,21 @@ jobs:
2929
path: "./node_modules"
3030
# Use the combo between node version, name, and SHA-256 hash of the lock file as cache key so that
3131
# if one of them changes the cache is invalidated/discarded
32-
key: ${{ matrix.version }}-cache-utils-node-modules-${{ hashFiles('./package-lock.json') }}
32+
key: ${{ matrix.version }}-cache-utilities-node-modules-${{ hashFiles('./package-lock.json') }}
3333
- name: Install dependencies
34-
# We can skip the install if there was a cache hit
34+
# We can skip the installation if there was a cache hit
3535
if: steps.cache-node-modules.outputs.cache-hit != 'true'
3636
# See https://github.com/npm/cli/issues/4475 to see why --foreground-scripts
3737
run: npm ci --foreground-scripts
3838
- name: Build packages
3939
# If there's a cache hit we still need to manually build the packages
4040
# this would otherwise have been done automatically as a part of the
41-
# postinstall npm hook
41+
# post-install npm hook
4242
if: steps.cache-node-modules.outputs.cache-hit == 'true'
4343
run: |
4444
npm run build -w packages/commons
4545
npm run build -w packages/logger & npm run build -w packages/tracer & npm run build -w packages/metrics
46-
- name: Lint
46+
- name: Run linting
4747
run: npm run lint -w packages/commons -w packages/logger -w packages/tracer -w packages/metrics
4848
- name: Run unit tests
4949
run: npm t -w packages/commons -w packages/logger -w packages/tracer -w packages/metrics
@@ -77,9 +77,11 @@ jobs:
7777
# invalidated/discarded for all.
7878
key: ${{ matrix.example }}-cache-examples-node-modules-${{ hashFiles('./examples/*/package-lock.json') }}
7979
- name: Install dependencies
80-
# We can skip the install if there was a cache hit
80+
# We can skip the installation if there was a cache hit
8181
if: steps.cache-node-modules.outputs.cache-hit != 'true'
8282
run: npm ci
83+
- name: Run linting
84+
run: npm run lint
8385
- name: Run tests
8486
run: npm t
8587
check-layer-publisher:
@@ -103,8 +105,12 @@ jobs:
103105
with:
104106
path: "./layer-publisher/node_modules"
105107
# Use the combo between example, name, and SHA-256 hash of the layer-publisher lock files as cache key.
106-
key: cache-layer-publisher-node-modules-${{ hashFiles('./layer-publisher/*/package-lock.json') }}
108+
key: cache-layer-publisher-node-modules-${{ hashFiles('./layer-publisher/package-lock.json') }}
107109
- name: Install Layer publisher
108-
# We can skip the install if there was a cache hit
110+
# We can skip the installation if there was a cache hit
109111
if: steps.cache-node-modules.outputs.cache-hit != 'true'
110112
run: npm ci
113+
- name: Run linting
114+
run: npm run lint
115+
- name: Run tests
116+
run: npm t

Diff for: .gitpod.yml

+2-11
Original file line numberDiff line numberDiff line change
@@ -5,22 +5,13 @@ tasks:
55
nvm use
66
# Install npm 8.x
77
npm i -g npm@next-8
8-
# Install monorepo packages
9-
npm ci --foreground-scripts
10-
# Install CDK exampels dependencies
11-
cd examples/cdk
12-
npm ci
13-
# Install SAM exampels dependencies
14-
cd ../sam
15-
npm ci
168
# Install AWS SAM CLI
179
wget https://github.com/aws/aws-sam-cli/releases/latest/download/aws-sam-cli-linux-x86_64.zip
1810
unzip aws-sam-cli-linux-x86_64.zip -d sam-installation
1911
sudo ./sam-installation/install
2012
rm -rf sam-installation aws-sam-cli-linux-*
21-
cd ../../
22-
# Setup husky hooks
23-
npm run init-environment
13+
# Install repo dependencies
14+
npm run setup-local
2415
vscode:
2516
extensions:
2617
- dbaeumer.vscode-eslint

Diff for: .husky/pre-commit

+7-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,10 @@
11
#!/bin/sh
22
. "$(dirname "$0")/_/husky.sh"
33

4-
npm run lerna-lint-fix
4+
npm run lint-fix -ws
5+
cd examples/sam && npm run lint-fix
6+
cd ../..
7+
cd examples/cdk && npm run lint-fix
8+
cd ../..
9+
cd layer-publisher && npm run lint-fix
10+
cd ..

Diff for: .husky/pre-push

+1-2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
#!/bin/sh
22
. "$(dirname "$0")/_/husky.sh"
33

4-
npm run lerna-lint-fix
5-
npm run test
4+
npm t -ws

Diff for: CONTRIBUTING.md

+6-8
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,7 @@ the [eslint extension](https://marketplace.visualstudio.com/items?itemName=dbaeu
8888
### Repo Layout
8989

9090
The AWS Lambda Powertools is a npm project written in [TypeScript](https://www.typescriptlang.org/).
91-
More specifically, it is a [monorepo managed using lerna](https://github.com/lerna/lerna#about).
91+
More specifically, it is a [monorepo managed using npm workspaces](https://docs.npmjs.com/cli/v8/using-npm/workspaces).
9292
If you're unfamiliar with any of these technologies, it is useful to learn about them and will make understanding the codebase easier but strictly not necessary for simple contributions.
9393

9494
The repo contains `packages/` directory that contains the Powertools utilities modules. For instance, the source code for the Logger utility can be found at the location `packages/logger` and so on.
@@ -126,9 +126,8 @@ As mentioned before, tests are split into groups thanks to [jest-runner-groups](
126126

127127
To run unit tests, you can either use:
128128

129-
* npm task `lerna-test:unit` (`npm run lerna-test:unit`) in root folder to run them all
130-
* npm task `test:unit` (`npm run test:unit`) in module folder (for example: `packages/metrics`) to run the module specific ones
131-
* jest directly `npx jest --group=unit` in module folder to run the module specific ones (You can run selective tests by restricting the group to the one you want. For instance `npx jest --group=unit/metrics/class`)
129+
* `npm test -ws` while in the root folder to run them all
130+
* `npm test -w packages/metrics` while in the root folder to run the module specific ones
132131

133132
#### e2e tests
134133

@@ -156,9 +155,8 @@ See `metrics/tests/e2e/basicFeatures.decorator.test.ts` as an example.
156155

157156
To run e2e tests, you can either use:
158157

159-
* npm task `lerna-test:e2e` (`npm run lerna-test:e2e`) in root folder
160-
* npm task `test:e2e` (`npm run test:e2e`) in module folder (for example: `packages/metrics`) to run the module specific ones
161-
* jest directly `npx jest --group=e2e` in module folder. (You can run selective tests by restricting the group to the one you want. For instance `npx jest --group=e2e/metrics/decorator`)
158+
* `npm test:e2e -ws` while in the root folder to run them all
159+
* `npm test:e2e -w packages/metrics` while in the root folder to run the module specific ones
162160

163161
Three important environment variables can be used:
164162

@@ -200,7 +198,7 @@ As part of the repo you will find an examples folder at the root. This folder co
200198

201199
To test your updates with these examples, you just have to:
202200

203-
1. Build your local version of *aws-lambda-powertools-typescript* npm packages with `npm run lerna-package` while in the root folder
201+
1. Build your local version of *aws-lambda-powertools-typescript* npm packages with `npm run package -ws` while in the root folder
204202
2. Move to the examples folder of your choice
205203
```sh
206204
cd packages/examples/cdk

Diff for: examples/cdk/.eslintrc.js

+67
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,67 @@
1+
module.exports = {
2+
env: {
3+
browser: false,
4+
es2020: true,
5+
jest: true,
6+
node: true,
7+
},
8+
extends: [ 'plugin:@typescript-eslint/eslint-recommended', 'plugin:@typescript-eslint/recommended' ],
9+
parser: '@typescript-eslint/parser',
10+
plugins: ['@typescript-eslint'],
11+
settings: {
12+
'import/resolver': {
13+
node: {},
14+
typescript: {
15+
project: './tsconfig.es.json',
16+
alwaysTryTypes: true,
17+
},
18+
},
19+
},
20+
rules: {
21+
'@typescript-eslint/ban-ts-ignore': ['off'],
22+
'@typescript-eslint/camelcase': ['off'],
23+
'@typescript-eslint/explicit-function-return-type': [ 'error', { allowExpressions: true } ],
24+
'@typescript-eslint/explicit-member-accessibility': 'error',
25+
'@typescript-eslint/indent': [ 'error', 2, { SwitchCase: 1 } ],
26+
'@typescript-eslint/interface-name-prefix': ['off'],
27+
'@typescript-eslint/member-delimiter-style': [ 'error', { multiline: { delimiter: 'none' } } ],
28+
'@typescript-eslint/member-ordering': [
29+
'error',
30+
{
31+
default: {
32+
memberTypes: [
33+
'signature',
34+
'public-field', // = ["public-static-field", "public-instance-field"]
35+
'protected-field', // = ["protected-static-field", "protected-instance-field"]
36+
'private-field', // = ["private-static-field", "private-instance-field"]
37+
'constructor',
38+
'public-method', // = ["public-static-method", "public-instance-method"]
39+
'protected-method', // = ["protected-static-method", "protected-instance-method"]
40+
'private-method', // = ["private-static-method", "private-instance-method"]
41+
],
42+
order: 'alphabetically',
43+
},
44+
},
45+
],
46+
'@typescript-eslint/no-explicit-any': 'error',
47+
'@typescript-eslint/no-inferrable-types': ['off'],
48+
'@typescript-eslint/no-unused-vars': [ 'error', { argsIgnorePattern: '^_' } ],
49+
'@typescript-eslint/no-use-before-define': ['off'],
50+
'@typescript-eslint/semi': [ 'error', 'always' ],
51+
'array-bracket-spacing': [ 'error', 'always', { singleValue: false } ],
52+
'arrow-body-style': [ 'error', 'as-needed' ],
53+
'computed-property-spacing': [ 'error', 'never' ],
54+
'func-style': [ 'warn', 'expression' ],
55+
indent: [ 'error', 2, { SwitchCase: 1 } ],
56+
'keyword-spacing': 'error',
57+
'newline-before-return': 2,
58+
'no-console': 0,
59+
'no-multi-spaces': [ 'error', { ignoreEOLComments: false } ],
60+
'no-multiple-empty-lines': [ 'error', { max: 1, maxBOF: 0 } ],
61+
'no-throw-literal': 'error',
62+
'object-curly-spacing': [ 'error', 'always' ],
63+
'prefer-arrow-callback': 'error',
64+
quotes: [ 'error', 'single', { allowTemplateLiterals: true } ],
65+
semi: [ 'error', 'always' ]
66+
},
67+
};

Diff for: examples/cdk/.gitignore

+1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
*.js
2+
!.eslintrc.js
23
!jest.config.js
34
*.d.ts
45
node_modules

0 commit comments

Comments
 (0)