Skip to content

Commit 7991d5b

Browse files
authored
style(logger): apply standardized formatting (#1457)
1 parent 5b3aef8 commit 7991d5b

39 files changed

+2155
-1766
lines changed

packages/logger/.eslintrc.js

Lines changed: 72 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,72 @@
1+
module.exports = {
2+
env: {
3+
browser: false,
4+
es2020: true,
5+
jest: true,
6+
node: true,
7+
},
8+
ignorePatterns: ['coverage', 'lib'],
9+
extends: [
10+
'plugin:@typescript-eslint/recommended',
11+
'plugin:prettier/recommended',
12+
],
13+
parser: '@typescript-eslint/parser',
14+
plugins: ['@typescript-eslint', 'prettier'],
15+
settings: {
16+
'import/resolver': {
17+
node: {},
18+
typescript: {
19+
project: './tsconfig.json',
20+
alwaysTryTypes: true,
21+
},
22+
},
23+
},
24+
rules: {
25+
'@typescript-eslint/explicit-function-return-type': [
26+
'error',
27+
{ allowExpressions: true },
28+
], // Enforce return type definitions for functions
29+
'@typescript-eslint/explicit-member-accessibility': 'error', // Enforce explicit accessibility modifiers on class properties and methods (public, private, protected)
30+
'@typescript-eslint/member-ordering': [
31+
// Standardize the order of class members
32+
'error',
33+
{
34+
default: {
35+
memberTypes: [
36+
'signature',
37+
'public-field',
38+
'protected-field',
39+
'private-field',
40+
'constructor',
41+
'public-method',
42+
'protected-method',
43+
'private-method',
44+
],
45+
order: 'alphabetically',
46+
},
47+
},
48+
],
49+
'@typescript-eslint/no-explicit-any': 'error', // Disallow usage of the any type
50+
'@typescript-eslint/no-unused-vars': ['error', { argsIgnorePattern: '^_' }], // Disallow unused variables, except for variables starting with an underscore
51+
'@typescript-eslint/no-use-before-define': ['off'], // Check if this rule is needed
52+
'no-unused-vars': 'off', // Disable eslint core rule, since it's replaced by @typescript-eslint/no-unused-vars
53+
// Rules from eslint core https://eslint.org/docs/latest/rules/
54+
'array-bracket-spacing': ['error', 'never'], // Disallow spaces inside of array brackets
55+
'computed-property-spacing': ['error', 'never'], // Disallow spaces inside of computed properties
56+
'func-style': ['warn', 'expression'], // Enforce function expressions instead of function declarations
57+
'keyword-spacing': 'error', // Enforce spaces after keywords and before parenthesis, e.g. if (condition) instead of if(condition)
58+
'padding-line-between-statements': [
59+
// Require an empty line before return statements
60+
'error',
61+
{ blankLine: 'always', prev: '*', next: 'return' },
62+
],
63+
'no-console': 0, // Allow console.log statements
64+
'no-multi-spaces': ['error', { ignoreEOLComments: false }], // Disallow multiple spaces except for comments
65+
'no-multiple-empty-lines': ['error', { max: 1, maxBOF: 0, maxEOF: 0 }], // Enforce no empty line at the beginning & end of files and max 1 empty line between consecutive statements
66+
'no-throw-literal': 'error', // Disallow throwing literals as exceptions, e.g. throw 'error' instead of throw new Error('error')
67+
'object-curly-spacing': ['error', 'always'], // Enforce spaces inside of curly braces in objects
68+
'prefer-arrow-callback': 'error', // Enforce arrow functions instead of anonymous functions for callbacks
69+
quotes: ['error', 'single', { allowTemplateLiterals: true }], // Enforce single quotes except for template strings
70+
semi: ['error', 'always'], // Require semicolons instead of ASI (automatic semicolon insertion) at the end of statements
71+
},
72+
};

packages/logger/jest.config.js

Lines changed: 19 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -3,43 +3,26 @@ module.exports = {
33
name: 'AWS Lambda Powertools utility: LOGGER',
44
color: 'cyan',
55
},
6-
'runner': 'groups',
7-
'preset': 'ts-jest',
8-
'transform': {
6+
runner: 'groups',
7+
preset: 'ts-jest',
8+
transform: {
99
'^.+\\.ts?$': 'ts-jest',
1010
},
11-
moduleFileExtensions: [ 'js', 'ts' ],
12-
'collectCoverageFrom': [
13-
'**/src/**/*.ts',
14-
'!**/node_modules/**',
15-
],
16-
'testMatch': ['**/?(*.)+(spec|test).ts'],
17-
'roots': [
18-
'<rootDir>/src',
19-
'<rootDir>/tests',
20-
],
21-
'testPathIgnorePatterns': [
22-
'/node_modules/',
23-
],
24-
'testEnvironment': 'node',
25-
'coveragePathIgnorePatterns': [
26-
'/node_modules/',
27-
'/types/',
28-
],
29-
'coverageThreshold': {
30-
'global': {
31-
'statements': 100,
32-
'branches': 100,
33-
'functions': 100,
34-
'lines': 100,
11+
moduleFileExtensions: ['js', 'ts'],
12+
collectCoverageFrom: ['**/src/**/*.ts', '!**/node_modules/**'],
13+
testMatch: ['**/?(*.)+(spec|test).ts'],
14+
roots: ['<rootDir>/src', '<rootDir>/tests'],
15+
testPathIgnorePatterns: ['/node_modules/'],
16+
testEnvironment: 'node',
17+
coveragePathIgnorePatterns: ['/node_modules/', '/types/'],
18+
coverageThreshold: {
19+
global: {
20+
statements: 100,
21+
branches: 100,
22+
functions: 100,
23+
lines: 100,
3524
},
3625
},
37-
'coverageReporters': [
38-
'json-summary',
39-
'text',
40-
'lcov'
41-
],
42-
'setupFiles': [
43-
'<rootDir>/tests/helpers/populateEnvironmentVariables.ts'
44-
]
45-
};
26+
coverageReporters: ['json-summary', 'text', 'lcov'],
27+
setupFiles: ['<rootDir>/tests/helpers/populateEnvironmentVariables.ts'],
28+
};

packages/logger/package.json

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -19,14 +19,15 @@
1919
"test:e2e": "jest --group=e2e",
2020
"watch": "jest --watch --group=unit",
2121
"build": "tsc",
22-
"lint": "eslint --ext .ts --no-error-on-unmatched-pattern src tests",
23-
"lint-fix": "eslint --fix --ext .ts --no-error-on-unmatched-pattern src tests",
22+
"lint": "eslint --ext .ts,.js --no-error-on-unmatched-pattern .",
23+
"lint-fix": "eslint --fix --ext .ts,.js --no-error-on-unmatched-pattern .",
2424
"package": "mkdir -p dist/ && npm pack && mv *.tgz dist/",
2525
"package-bundle": "../../package-bundler.sh logger-bundle ./dist",
2626
"prepare": "npm run build"
2727
},
2828
"lint-staged": {
29-
"*.ts": "npm run lint-fix"
29+
"*.ts": "npm run lint-fix",
30+
"*.js": "npm run lint-fix"
3031
},
3132
"homepage": "https://github.com/awslabs/aws-lambda-powertools-typescript/tree/main/packages/logging#readme",
3233
"license": "MIT",
@@ -59,4 +60,4 @@
5960
"serverless",
6061
"nodejs"
6162
]
62-
}
63+
}

0 commit comments

Comments
 (0)