Skip to content

Commit 72da0d0

Browse files
committed
Fixed linting and added to pre-commit hook
1 parent 8b72afa commit 72da0d0

File tree

5 files changed

+306
-291
lines changed

5 files changed

+306
-291
lines changed

.husky/pre-commit

Lines changed: 22 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,30 @@
11
#!/usr/bin/env sh
2-
# Pre-commit hook to run Snyk and Talisman scans, completing both before deciding to commit
2+
# Pre-commit hook to run lint, Snyk and Talisman scans, completing all before deciding to commit
33

44
# Function to check if a command exists
55
command_exists() {
66
command -v "$1" >/dev/null 2>&1
77
}
88

9+
# Allow bypassing the hook with an environment variable
10+
if [ "$SKIP_HOOK" = "1" ]; then
11+
echo "Skipping lint, Snyk and Talisman scans (SKIP_HOOK=1)."
12+
exit 0
13+
fi
14+
15+
# Run ESLint check first
16+
echo "Running ESLint check..."
17+
npm run lint
18+
lint_exit_code=$?
19+
20+
if [ $lint_exit_code -ne 0 ]; then
21+
echo "ESLint check failed. Please fix the linting issues and try again."
22+
echo "You can run 'npm run format' to auto-fix most issues."
23+
exit 1
24+
fi
25+
26+
echo "ESLint check passed."
27+
928
# Check if Snyk is installed
1029
if ! command_exists snyk; then
1130
echo "Error: Snyk is not installed. Please install it and try again."
@@ -18,12 +37,6 @@ if ! command_exists talisman; then
1837
exit 1
1938
fi
2039

21-
# Allow bypassing the hook with an environment variable
22-
if [ "$SKIP_HOOK" = "1" ]; then
23-
echo "Skipping Snyk and Talisman scans (SKIP_HOOK=1)."
24-
exit 0
25-
fi
26-
2740
# Initialize variables to track scan results
2841
snyk_failed=false
2942
talisman_failed=false
@@ -63,7 +76,7 @@ if [ "$snyk_failed" = true ] || [ "$talisman_failed" = true ]; then
6376
exit 1
6477
fi
6578

66-
# If both scans pass, allow the commit
67-
echo "All scans passed. Proceeding with commit.cd ."
79+
# If all checks pass, allow the commit
80+
echo "All checks passed (ESLint, Snyk, Talisman). Proceeding with commit."
6881
rm -f snyk_output.log talisman_output.log
6982
exit 0

.talismanrc

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
11
fileignoreconfig:
2+
- filename: .husky/pre-commit
3+
checksum: 52a664f536cf5d1be0bea19cb6031ca6e8107b45b6314fe7d47b7fad7d800632
24
- filename: test/sanity-check/api/user-test.js
3-
checksum: c82c76ef1a4d175044b9a30a82ed20f004320ec297ea37f27fdbd5c3fec9ff34
5+
checksum: 6bb8251aad584e09f4d963a913bd0007e5f6e089357a44c3fb1529e3fda5509d
46
version: ""

lib/contentstack.js

Lines changed: 53 additions & 53 deletions
Original file line numberDiff line numberDiff line change
@@ -8,13 +8,13 @@ import getUserAgent from './core/Util.js'
88
import contentstackClient from './contentstackClient.js'
99
import httpClient from './core/contentstackHTTPClient.js'
1010
const regionHostMap = {
11-
NA: 'api.contentstack.io',
12-
EU: 'eu-api.contentstack.com',
13-
AU: 'au-api.contentstack.com',
14-
AZURE_NA: 'azure-na-api.contentstack.com',
15-
AZURE_EU: 'azure-eu-api.contentstack.com',
16-
GCP_NA: 'gcp-na-api.contentstack.com',
17-
GCP_EU: 'gcp-eu-api.contentstack.com'
11+
NA: 'api.contentstack.io',
12+
EU: 'eu-api.contentstack.com',
13+
AU: 'au-api.contentstack.com',
14+
AZURE_NA: 'azure-na-api.contentstack.com',
15+
AZURE_EU: 'azure-eu-api.contentstack.com',
16+
GCP_NA: 'gcp-na-api.contentstack.com',
17+
GCP_EU: 'gcp-eu-api.contentstack.com'
1818
}
1919

2020
/**
@@ -169,56 +169,56 @@ const regionHostMap = {
169169
* @prop {string=} params.integration - Integration name and version e.g react/version
170170
* @returns Contentstack.Client
171171
*/
172-
export function client(params = {}) {
173-
let defaultHostName
172+
export function client (params = {}) {
173+
let defaultHostName
174174

175-
if (params.region) {
176-
const region = params.region.toUpperCase()
177-
if (!regionHostMap[region]) {
178-
throw new Error(`Invalid region '${params.region}' provided. Allowed regions are: ${Object.keys(regionHostMap).join(', ')}`)
179-
}
180-
defaultHostName = regionHostMap[region]
181-
} else if (params.host) {
182-
defaultHostName = params.host
183-
} else {
184-
defaultHostName = regionHostMap['NA']
175+
if (params.region) {
176+
const region = params.region.toUpperCase()
177+
if (!regionHostMap[region]) {
178+
throw new Error(`Invalid region '${params.region}' provided. Allowed regions are: ${Object.keys(regionHostMap).join(', ')}`)
185179
}
180+
defaultHostName = regionHostMap[region]
181+
} else if (params.host) {
182+
defaultHostName = params.host
183+
} else {
184+
defaultHostName = regionHostMap['NA']
185+
}
186186

187-
const defaultParameter = {
188-
defaultHostName: defaultHostName
189-
}
187+
const defaultParameter = {
188+
defaultHostName: defaultHostName
189+
}
190190

191-
const sdkAgent = `contentstack-management-javascript/${packages.version}`
192-
const userAgentHeader = getUserAgent(sdkAgent,
193-
params.application,
194-
params.integration,
195-
params.feature
196-
)
197-
const requiredHeaders = {
198-
'X-User-Agent': sdkAgent,
199-
'User-Agent': userAgentHeader
200-
}
191+
const sdkAgent = `contentstack-management-javascript/${packages.version}`
192+
const userAgentHeader = getUserAgent(sdkAgent,
193+
params.application,
194+
params.integration,
195+
params.feature
196+
)
197+
const requiredHeaders = {
198+
'X-User-Agent': sdkAgent,
199+
'User-Agent': userAgentHeader
200+
}
201201

202-
if (params.authtoken) {
203-
requiredHeaders.authtoken = params.authtoken
204-
}
205-
if (params.authorization) {
206-
requiredHeaders.authorization = params.authorization
207-
}
208-
if (params.early_access) {
209-
requiredHeaders.early_access = params.early_access.join(',')
210-
}
211-
params = {
212-
...defaultParameter,
213-
...clonedeep(params)
214-
}
202+
if (params.authtoken) {
203+
requiredHeaders.authtoken = params.authtoken
204+
}
205+
if (params.authorization) {
206+
requiredHeaders.authorization = params.authorization
207+
}
208+
if (params.early_access) {
209+
requiredHeaders.early_access = params.early_access.join(',')
210+
}
211+
params = {
212+
...defaultParameter,
213+
...clonedeep(params)
214+
}
215215

216-
params.headers = {
217-
...params.headers,
218-
...requiredHeaders
219-
}
220-
const http = httpClient(params)
221-
return contentstackClient({
222-
http: http
223-
})
216+
params.headers = {
217+
...params.headers,
218+
...requiredHeaders
219+
}
220+
const http = httpClient(params)
221+
return contentstackClient({
222+
http: http
223+
})
224224
}

0 commit comments

Comments
 (0)