Skip to content

Commit ba90f16

Browse files
authored
Merge pull request #234 from 18F/add_linting
Add linting support
2 parents a59151a + 0eebbaa commit ba90f16

24 files changed

+1230
-2386
lines changed

.circleci/config.yml

Lines changed: 101 additions & 147 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,53 @@
11
version: 2.1
2+
3+
restore_npm_cache: &restore_npm_cache
4+
restore_cache:
5+
keys:
6+
- v1-dependencies-{{ checksum "package.json" }}
7+
- v1-dependencies-
8+
9+
install_npm_packages: &install_npm_packages
10+
run:
11+
name: install dependencies
12+
command: npm install
13+
14+
save_npm_cache: &save_npm_cache
15+
save_cache:
16+
paths:
17+
- ./node_modules
18+
key: v1-dependencies-{{ checksum "package.json" }}
19+
20+
fix_file_suffixes_for_cloud_gov: &fix_file_suffixes_for_cloud_gov
21+
run:
22+
name: Delete Config.js and drop sufffix on Config.js.cloudgov
23+
command: |
24+
rm ./src/config.js
25+
mv ./src/config.js.cloudgov ./src/config.js
26+
rm knexfile.js
27+
mv knexfile.js.cloudgov knexfile.js
28+
29+
install_cf_cli: &install_cf_cli
30+
run:
31+
name: Install CF CLI
32+
command: |
33+
sudo curl -v -L -o cf8-cli-installer_8.7.4_x86-64.deb 'https://packages.cloudfoundry.org/stable?release=debian64&version=8.7.4'
34+
sudo dpkg -i cf8-cli-installer_8.7.4_x86-64.deb
35+
236
jobs:
3-
develop_deploy:
37+
lint_js:
438
docker:
5-
- image: cimg/node:16.19.1-browsers
39+
- image: cimg/node:20.11.0-browsers
40+
steps:
41+
- checkout
42+
- *restore_npm_cache
43+
- *install_npm_packages
44+
- *save_npm_cache
45+
- run:
46+
name: lint javascript
47+
command: npm run lint
48+
test:
49+
docker:
50+
- image: cimg/node:20.11.0-browsers
651
environment:
752
POSTGRES_USER: postgres
853
NODE_ENV: test
@@ -11,25 +56,20 @@ jobs:
1156
POSTGRES_DB: analytics-api-test
1257
steps:
1358
- checkout
14-
15-
- restore_cache:
16-
keys:
17-
- v1-dependencies-{{ checksum "package.json" }}
18-
- v1-dependencies-
19-
20-
- run:
21-
name: install dependencies
22-
command: npm install
23-
24-
- save_cache:
25-
paths:
26-
- ./node_modules
27-
key: v1-dependencies-{{ checksum "package.json" }}
28-
59+
- *restore_npm_cache
60+
- *install_npm_packages
61+
- *save_npm_cache
2962
- run:
30-
name: run tests
31-
command: npm test
32-
63+
name: unit test javascript
64+
command: npm test
65+
development_env_deploy:
66+
docker:
67+
- image: cimg/node:20.11.0-browsers
68+
steps:
69+
- checkout
70+
- *restore_npm_cache
71+
- *install_npm_packages
72+
- *save_npm_cache
3373
- run:
3474
name: Replace Data URL in manifest.yml file when deploying to develop
3575
command: |
@@ -39,26 +79,12 @@ jobs:
3979
sed -i 's@- analytics-reporter-database@- analytics-reporter-database-develop@g' manifest.yml
4080
mv manifest.yml manifest.yml.src
4181
envsubst < manifest.yml.src > manifest.yml
42-
4382
- run:
4483
name: Run sed on entrypoint.sh when deploying to develop
4584
command: |
4685
sed -i 's@NEW_RELIC_APP_NAME="analytics-reporter-api"@NEW_RELIC_APP_NAME="analytics-reporter-api-develop"@g' entrypoint.sh
47-
48-
- run:
49-
name: Delete Config.js and drop sufffix on Config.js.cloudgov
50-
command: |
51-
rm ./src/config.js
52-
mv ./src/config.js.cloudgov ./src/config.js
53-
rm knexfile.js
54-
mv knexfile.js.cloudgov knexfile.js
55-
56-
- run:
57-
name: Install CF CLI
58-
command: |
59-
sudo curl -v -L -o cf8-cli-installer_8.7.4_x86-64.deb 'https://packages.cloudfoundry.org/stable?release=debian64&version=8.7.4'
60-
sudo dpkg -i cf8-cli-installer_8.7.4_x86-64.deb
61-
86+
- *fix_file_suffixes_for_cloud_gov
87+
- *install_cf_cli
6288
- run:
6389
name: deploy
6490
command: |
@@ -71,37 +97,14 @@ jobs:
7197
cf set-env analytics-reporter-api-develop API_DATA_GOV_SECRET "$API_SECRET_LOWER"
7298
cf restage analytics-reporter-api-develop
7399
cf logout
74-
75-
staging_deploy:
100+
staging_env_deploy:
76101
docker:
77-
- image: cimg/node:16.19.1-browsers
78-
environment:
79-
POSTGRES_USER: postgres
80-
NODE_ENV: test
81-
- image: circleci/postgres:9.5-alpine
82-
environment:
83-
POSTGRES_DB: analytics-api-test
102+
- image: cimg/node:20.11.0-browsers
84103
steps:
85104
- checkout
86-
87-
- restore_cache:
88-
keys:
89-
- v1-dependencies-{{ checksum "package.json" }}
90-
- v1-dependencies-
91-
92-
- run:
93-
name: install dependencies
94-
command: npm install
95-
96-
- save_cache:
97-
paths:
98-
- ./node_modules
99-
key: v1-dependencies-{{ checksum "package.json" }}
100-
101-
- run:
102-
name: run tests
103-
command: npm test
104-
105+
- *restore_npm_cache
106+
- *install_npm_packages
107+
- *save_npm_cache
105108
- run:
106109
name: Replace Data URL in manifest.yml file when deploying to staging
107110
command: |
@@ -111,26 +114,12 @@ jobs:
111114
sed -i 's@- analytics-reporter-database@- analytics-reporter-database-staging@g' manifest.yml
112115
mv manifest.yml manifest.yml.src
113116
envsubst < manifest.yml.src > manifest.yml
114-
115117
- run:
116118
name: Run sed on entrypoint.sh when deploying to staging
117119
command: |
118120
sed -i 's@NEW_RELIC_APP_NAME="analytics-reporter-api"@NEW_RELIC_APP_NAME="analytics-reporter-api-staging"@g' entrypoint.sh
119-
120-
- run:
121-
name: Delete Knexfile.js and drop sufffix on Knexfile.js.cloudgov
122-
command: |
123-
rm knexfile.js
124-
mv knexfile.js.cloudgov knexfile.js
125-
rm ./src/config.js
126-
mv ./src/config.js.cloudgov ./src/config.js
127-
128-
- run:
129-
name: Install CF CLI
130-
command: |
131-
sudo curl -v -L -o cf8-cli-installer_8.7.4_x86-64.deb 'https://packages.cloudfoundry.org/stable?release=debian64&version=8.7.4'
132-
sudo dpkg -i cf8-cli-installer_8.7.4_x86-64.deb
133-
121+
- *fix_file_suffixes_for_cloud_gov
122+
- *install_cf_cli
134123
- run:
135124
name: deploy
136125
command: |
@@ -143,37 +132,14 @@ jobs:
143132
cf set-env analytics-reporter-api-staging API_DATA_GOV_SECRET "$API_SECRET_LOWER"
144133
cf restage analytics-reporter-api-staging
145134
cf logout
146-
147-
main_deploy:
135+
production_env_deploy:
148136
docker:
149-
- image: cimg/node:16.19.1-browsers
150-
environment:
151-
POSTGRES_USER: postgres
152-
NODE_ENV: test
153-
- image: circleci/postgres:9.5-alpine
154-
environment:
155-
POSTGRES_DB: analytics-api-test
137+
- image: cimg/node:20.11.0-browsers
156138
steps:
157139
- checkout
158-
159-
- restore_cache:
160-
keys:
161-
- v1-dependencies-{{ checksum "package.json" }}
162-
- v1-dependencies-
163-
164-
- run:
165-
name: install dependencies
166-
command: npm install
167-
168-
- save_cache:
169-
paths:
170-
- ./node_modules
171-
key: v1-dependencies-{{ checksum "package.json" }}
172-
173-
- run:
174-
name: run tests
175-
command: npm test
176-
140+
- *restore_npm_cache
141+
- *install_npm_packages
142+
- *save_npm_cache
177143
- run:
178144
name: Replace Data URL in manifest.yml file when deploying to production
179145
command: |
@@ -183,26 +149,12 @@ jobs:
183149
sed -i 's@- analytics-reporter-database@- analytics-reporter-database-production@g' manifest.yml
184150
mv manifest.yml manifest.yml.src
185151
envsubst < manifest.yml.src > manifest.yml
186-
187152
- run:
188153
name: Run sed on entrypoint.sh when deploying to main
189154
command: |
190155
sed -i 's@NEW_RELIC_APP_NAME="analytics-reporter-api"@NEW_RELIC_APP_NAME="analytics-reporter-api-production"@g' entrypoint.sh
191-
192-
- run:
193-
name: Delete Knexfile.js and drop sufffix on Knexfile.js.cloudgov
194-
command: |
195-
rm knexfile.js
196-
mv knexfile.js.cloudgov knexfile.js
197-
rm ./src/config.js
198-
mv ./src/config.js.cloudgov ./src/config.js
199-
200-
- run:
201-
name: Install CF CLI
202-
command: |
203-
sudo curl -v -L -o cf8-cli-installer_8.7.4_x86-64.deb 'https://packages.cloudfoundry.org/stable?release=debian64&version=8.7.4'
204-
sudo dpkg -i cf8-cli-installer_8.7.4_x86-64.deb
205-
156+
- *fix_file_suffixes_for_cloud_gov
157+
- *install_cf_cli
206158
- run:
207159
name: deploy
208160
command: |
@@ -216,28 +168,30 @@ jobs:
216168
cf restage analytics-reporter-api-production
217169
cf logout
218170
219-
workflows:
220-
develop_workflow:
221-
jobs:
222-
- develop_deploy:
223-
filters:
224-
branches:
225-
only:
171+
ci:
172+
jobs:
173+
- lint
174+
- test:
175+
requires:
176+
- lint
177+
- development_env_deploy:
178+
requires:
179+
- test
180+
filters:
181+
branches:
182+
only:
226183
- develop
227-
228-
staging:
229-
jobs:
230-
- staging_deploy:
231-
filters:
232-
branches:
233-
only:
234-
- stage
235-
236-
main_workflow:
237-
jobs:
238-
- main_deploy:
239-
filters:
240-
branches:
241-
only:
184+
- staging_env_deploy:
185+
requires:
186+
- test
187+
filters:
188+
branches:
189+
only:
190+
- staging
191+
- production_env_deploy:
192+
requires:
193+
- test
194+
filters:
195+
branches:
196+
only:
242197
- master
243-

eslint.config.js

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
const eslintPluginPrettierRecommended = require("eslint-plugin-prettier/recommended");
2+
3+
module.exports = [eslintPluginPrettierRecommended];

index.js

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
11
if (process.env.NEW_RELIC_APP_NAME) {
2-
console.log("Starting New Relic");
3-
require("newrelic");
2+
console.log("Starting New Relic");
3+
require("newrelic");
44
}
55

6-
const app = require('./src/app');
7-
const config = require('./src/config');
8-
const logger = require('./src/logger');
6+
const app = require("./src/app");
7+
const config = require("./src/config");
8+
const logger = require("./src/logger");
99

1010
app.listen(config.port, () => {
1111
console.log(`Listening on ${config.port}`);

knexfile.js

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,14 @@
11
module.exports = {
22
development: {
3-
client: 'postgresql',
3+
client: "postgresql",
44
connection: {
5-
user: process.env.POSTGRES_USER || 'postgres',
6-
password: process.env.POSTGRES_PASSWORD || '123abc',
7-
database: process.env.POSTGRES_DATABASE || 'analytics-reporter',
8-
}
5+
user: process.env.POSTGRES_USER || "postgres",
6+
password: process.env.POSTGRES_PASSWORD || "123abc",
7+
database: process.env.POSTGRES_DATABASE || "analytics-reporter",
8+
},
99
},
1010
production: {
11-
client: 'postgresql',
11+
client: "postgresql",
1212
connection: {
1313
host: process.env.POSTGRES_HOST,
1414
user: process.env.POSTGRES_USER,
@@ -17,20 +17,20 @@ module.exports = {
1717
},
1818
pool: {
1919
min: 2,
20-
max: 10
20+
max: 10,
2121
},
2222
migrations: {
23-
tableName: 'knex_migrations'
24-
}
23+
tableName: "knex_migrations",
24+
},
2525
},
2626
test: {
27-
client: 'postgresql',
27+
client: "postgresql",
2828
connection: {
29-
user: process.env.CIRCLECI ? 'postgres' : undefined,
30-
database: 'analytics-api-test'
29+
user: process.env.CIRCLECI ? "postgres" : undefined,
30+
database: "analytics-api-test",
3131
},
3232
migrations: {
33-
tableName: 'knex_migrations'
34-
}
35-
}
33+
tableName: "knex_migrations",
34+
},
35+
},
3636
};

0 commit comments

Comments
 (0)