Skip to content

Commit

Permalink
Enhancement: refactor with max-len 120.
Browse files Browse the repository at this point in the history
  • Loading branch information
rash805115 committed May 28, 2023
1 parent f22bfa5 commit b9671b4
Show file tree
Hide file tree
Showing 14 changed files with 51 additions and 244 deletions.
13 changes: 3 additions & 10 deletions .eslintrc.js
Original file line number Diff line number Diff line change
Expand Up @@ -49,16 +49,9 @@ module.exports = {
],
},
],
'jsonc/sort-keys': [
'error',
'asc',
{ caseSensitive: true, minKeys: 2, natural: false },
],
'sort-keys': [
'error',
'asc',
{ caseSensitive: true, minKeys: 2, natural: false },
],
'jsonc/sort-keys': ['error', 'asc', { caseSensitive: true, minKeys: 2, natural: false }],
'max-len': ['error', { code: 120, ignoreStrings: true }],
'sort-keys': ['error', 'asc', { caseSensitive: true, minKeys: 2, natural: false }],
'spellcheck/spell-checker': [
1,
{
Expand Down
1 change: 1 addition & 0 deletions .prettierrc
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
{
"printWidth": 120,
"singleQuote": true,
"trailingComma": "all"
}
1 change: 1 addition & 0 deletions dictionary.dic
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ dic
eslintrc
ispec
jsonc
len
nginx
octo
promisify
Expand Down
66 changes: 9 additions & 57 deletions src/v0/models/app/app.model.ts
Original file line number Diff line number Diff line change
Expand Up @@ -66,18 +66,9 @@ export class App implements IModel<App> {
const diff: Diff[] = [];

for (const region of this.regions) {
const regionInLatest = latest.regions.find(
(r) => r.regionId === region.regionId,
);
const regionInLatest = latest.regions.find((r) => r.regionId === region.regionId);
if (!regionInLatest) {
diff.push(
new Diff(
DiffAction.DELETE,
this.getContext(),
'region',
region.regionId,
),
);
diff.push(new Diff(DiffAction.DELETE, this.getContext(), 'region', region.regionId));
} else {
const regionDiff = region.diff(regionInLatest);
if (regionDiff.length !== 0) {
Expand All @@ -88,14 +79,7 @@ export class App implements IModel<App> {

for (const region of latest.regions) {
if (!this.regions.find((r) => r.regionId === region.regionId)) {
diff.push(
new Diff(
DiffAction.ADD,
this.getContext(),
'region',
region.regionId,
),
);
diff.push(new Diff(DiffAction.ADD, this.getContext(), 'region', region.regionId));

const regionDiff = region.diffAdd();
if (regionDiff.length !== 0) {
Expand All @@ -105,18 +89,9 @@ export class App implements IModel<App> {
}

for (const server of this.servers) {
const serverInLatest = latest.servers.find(
(s) => s.serverKey === server.serverKey,
);
const serverInLatest = latest.servers.find((s) => s.serverKey === server.serverKey);
if (!serverInLatest) {
diff.push(
new Diff(
DiffAction.DELETE,
this.getContext(),
'server',
server.serverKey,
),
);
diff.push(new Diff(DiffAction.DELETE, this.getContext(), 'server', server.serverKey));
} else {
const serverDiff = server.diff(serverInLatest);
if (serverDiff.length !== 0) {
Expand All @@ -127,14 +102,7 @@ export class App implements IModel<App> {

for (const server of latest.servers) {
if (!this.servers.find((s) => s.serverKey === server.serverKey)) {
diff.push(
new Diff(
DiffAction.ADD,
this.getContext(),
'server',
server.serverKey,
),
);
diff.push(new Diff(DiffAction.ADD, this.getContext(), 'server', server.serverKey));

const serverDiff = server.diffAdd();
if (serverDiff.length !== 0) {
Expand All @@ -144,18 +112,9 @@ export class App implements IModel<App> {
}

for (const support of this.supports) {
const supportInLatest = latest.supports.find(
(s) => s.serverKey === support.serverKey,
);
const supportInLatest = latest.supports.find((s) => s.serverKey === support.serverKey);
if (!supportInLatest) {
diff.push(
new Diff(
DiffAction.DELETE,
this.getContext(),
'support',
support.serverKey,
),
);
diff.push(new Diff(DiffAction.DELETE, this.getContext(), 'support', support.serverKey));
} else {
const supportDiff = support.diff(supportInLatest);
if (supportDiff.length !== 0) {
Expand All @@ -166,14 +125,7 @@ export class App implements IModel<App> {

for (const support of latest.supports) {
if (!this.supports.find((s) => s.serverKey === support.serverKey)) {
diff.push(
new Diff(
DiffAction.ADD,
this.getContext(),
'support',
support.serverKey,
),
);
diff.push(new Diff(DiffAction.ADD, this.getContext(), 'support', support.serverKey));

const supportDiff = support.diffAdd();
if (supportDiff.length !== 0) {
Expand Down
4 changes: 1 addition & 3 deletions src/v0/models/deployment/deployment.model.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,6 @@ export class Deployment implements IModel<Deployment> {
}

getContext(): string {
return [`deployment=${this.deploymentTag}`, this.context.getContext()].join(
',',
);
return [`deployment=${this.deploymentTag}`, this.context.getContext()].join(',');
}
}
9 changes: 2 additions & 7 deletions src/v0/models/environment/environment.model.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,17 +5,12 @@ import { Environment } from './environment.model';
describe('Environment UT', () => {
describe('clone()', () => {
it('should clone all fields', () => {
const environment = new Environment(
new AwsRegion(new App('test'), 'aws-us-east-1'),
'qa',
);
const environment = new Environment(new AwsRegion(new App('test'), 'aws-us-east-1'), 'qa');
environment.environmentVariables.set('key', 'value');

const duplicate = environment.clone();

expect(duplicate.getContext()).toBe(
'environment=qa,region=aws-us-east-1,app=test',
);
expect(duplicate.getContext()).toBe('environment=qa,region=aws-us-east-1,app=test');
expect(duplicate.environmentName).toBe('qa');
expect(duplicate.environmentVariables.get('key')).toBe('value');
});
Expand Down
27 changes: 6 additions & 21 deletions src/v0/models/environment/environment.model.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,25 +29,13 @@ export class Environment implements IModel<Environment> {

for (const [key, value] of this.environmentVariables) {
if (!latest.environmentVariables.has(key)) {
diff.push(
new Diff(
DiffAction.DELETE,
this.getContext(),
'environmentVariables',
{ key, value },
),
);
diff.push(new Diff(DiffAction.DELETE, this.getContext(), 'environmentVariables', { key, value }));
} else if (latest.environmentVariables.get(key) !== value) {
diff.push(
new Diff(
DiffAction.UPDATE,
this.getContext(),
'environmentVariables',
{
key,
value: latest.environmentVariables.get(key),
},
),
new Diff(DiffAction.UPDATE, this.getContext(), 'environmentVariables', {
key,
value: latest.environmentVariables.get(key),
}),
);
}
}
Expand Down Expand Up @@ -85,9 +73,6 @@ export class Environment implements IModel<Environment> {
}

getContext(): string {
return [
`environment=${this.environmentName}`,
this.context.getContext(),
].join(',');
return [`environment=${this.environmentName}`, this.context.getContext()].join(',');
}
}
43 changes: 6 additions & 37 deletions src/v0/models/region/region.model.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,11 +20,7 @@ export class Region implements IModel<Region> {

addEnvironment(environment: Environment): void {
// Check for duplicates.
if (
this.environments.find(
(e) => e.environmentName === environment.environmentName,
)
) {
if (this.environments.find((e) => e.environmentName === environment.environmentName)) {
throw new Error('Environment already exists!');
}

Expand All @@ -45,18 +41,9 @@ export class Region implements IModel<Region> {
const diff: Diff[] = [];

for (const environment of this.environments) {
const environmentInLatest = latest.environments.find(
(e) => e.environmentName === environment.environmentName,
);
const environmentInLatest = latest.environments.find((e) => e.environmentName === environment.environmentName);
if (!environmentInLatest) {
diff.push(
new Diff(
DiffAction.DELETE,
this.getContext(),
'environment',
environment.environmentName,
),
);
diff.push(new Diff(DiffAction.DELETE, this.getContext(), 'environment', environment.environmentName));
} else {
const environmentDiff = environment.diff(environmentInLatest);
if (environmentDiff.length !== 0) {
Expand All @@ -66,19 +53,8 @@ export class Region implements IModel<Region> {
}

for (const environment of latest.environments) {
if (
!this.environments.find(
(e) => e.environmentName === environment.environmentName,
)
) {
diff.push(
new Diff(
DiffAction.ADD,
this.getContext(),
'environment',
environment.environmentName,
),
);
if (!this.environments.find((e) => e.environmentName === environment.environmentName)) {
diff.push(new Diff(DiffAction.ADD, this.getContext(), 'environment', environment.environmentName));

const environmentDiff = environment.diffAdd();
if (environmentDiff.length !== 0) {
Expand All @@ -97,14 +73,7 @@ export class Region implements IModel<Region> {
const diff: Diff[] = [];

for (const environment of this.environments) {
diff.push(
new Diff(
DiffAction.ADD,
this.getContext(),
'environment',
environment.environmentName,
),
);
diff.push(new Diff(DiffAction.ADD, this.getContext(), 'environment', environment.environmentName));

const environmentDiff = environment.diffAdd();
if (environmentDiff.length !== 0) {
Expand Down
41 changes: 6 additions & 35 deletions src/v0/models/server/server.model.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,7 @@ export class Server implements IModel<Server> {

addDeployment(deployment: Deployment): void {
// Check for duplicates.
if (
this.deployments.find((d) => d.deploymentTag === deployment.deploymentTag)
) {
if (this.deployments.find((d) => d.deploymentTag === deployment.deploymentTag)) {
throw new Error('Deployment already exists!');
}

Expand All @@ -40,18 +38,9 @@ export class Server implements IModel<Server> {
const diff: Diff[] = [];

for (const deployment of this.deployments) {
const deploymentInLatest = latest.deployments.find(
(d) => d.deploymentTag === deployment.deploymentTag,
);
const deploymentInLatest = latest.deployments.find((d) => d.deploymentTag === deployment.deploymentTag);
if (!deploymentInLatest) {
diff.push(
new Diff(
DiffAction.DELETE,
this.getContext(),
'deployment',
deployment.deploymentTag,
),
);
diff.push(new Diff(DiffAction.DELETE, this.getContext(), 'deployment', deployment.deploymentTag));
} else {
const deploymentDiff = deployment.diff(deploymentInLatest);
if (deploymentDiff.length !== 0) {
Expand All @@ -61,19 +50,8 @@ export class Server implements IModel<Server> {
}

for (const deployment of latest.deployments) {
if (
!this.deployments.find(
(d) => d.deploymentTag === deployment.deploymentTag,
)
) {
diff.push(
new Diff(
DiffAction.ADD,
this.getContext(),
'deployment',
deployment.deploymentTag,
),
);
if (!this.deployments.find((d) => d.deploymentTag === deployment.deploymentTag)) {
diff.push(new Diff(DiffAction.ADD, this.getContext(), 'deployment', deployment.deploymentTag));

const deploymentDiff = deployment.diffAdd();
if (deploymentDiff.length !== 0) {
Expand All @@ -92,14 +70,7 @@ export class Server implements IModel<Server> {
const diff: Diff[] = [];

for (const deployment of this.deployments) {
diff.push(
new Diff(
DiffAction.ADD,
this.getContext(),
'deployment',
deployment.deploymentTag,
),
);
diff.push(new Diff(DiffAction.ADD, this.getContext(), 'deployment', deployment.deploymentTag));

const deploymentDiff = deployment.diffAdd();
if (deploymentDiff.length !== 0) {
Expand Down
Loading

0 comments on commit b9671b4

Please sign in to comment.