Skip to content

Commit dbde5ab

Browse files
authored
Format typescript sources at max_line_length=100 (#7205)
* Enable max_line_length = 100 for typescript sources * Format typescript files to resolve check/ts-lint Executed check/npm run fix
1 parent 75f0dd3 commit dbde5ab

20 files changed

Lines changed: 56 additions & 232 deletions

.editorconfig

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -34,8 +34,6 @@ max_line_length = 100
3434
[{*.ts,*.js}]
3535
# Google style guidelines use 2.
3636
indent_size = 2
37-
# TODO: remove the next setting after reformatting TypeScript code.
38-
max_line_length = 0
3937

4038
[*.json]
4139
# Not stated explicitly in Google's guidelines, but the examples use 2.

cirq-web/cirq_ts/e2e/bloch_sphere/bloch_sphere_e2e_test.ts

Lines changed: 6 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -79,14 +79,9 @@ describe('Bloch sphere', () => {
7979
const {width, height} = expected;
8080
const diff = new PNG.PNG({width, height});
8181

82-
const pixels = pixelmatch(
83-
expected.data,
84-
actual.data,
85-
diff.data,
86-
width,
87-
height,
88-
{threshold: 0.1},
89-
);
82+
const pixels = pixelmatch(expected.data, actual.data, diff.data, width, height, {
83+
threshold: 0.1,
84+
});
9085

9186
expect(pixels).to.equal(0);
9287
});
@@ -112,14 +107,9 @@ describe('Bloch sphere', () => {
112107
const {width, height} = expected;
113108
const diff = new PNG.PNG({width, height});
114109

115-
const pixels = pixelmatch(
116-
expected.data,
117-
actual.data,
118-
diff.data,
119-
width,
120-
height,
121-
{threshold: 0.1},
122-
);
110+
const pixels = pixelmatch(expected.data, actual.data, diff.data, width, height, {
111+
threshold: 0.1,
112+
});
123113

124114
expect(pixels).to.equal(0);
125115
});

cirq-web/cirq_ts/e2e/circuit/circuit_e2e_test.ts

Lines changed: 4 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -88,21 +88,14 @@ describe('Circuit', () => {
8888
});
8989

9090
it('with limited gates matches the gold copy', () => {
91-
const expected = PNG.PNG.sync.read(
92-
readFileSync('e2e/circuit/circuit_expected.png'),
93-
);
91+
const expected = PNG.PNG.sync.read(readFileSync('e2e/circuit/circuit_expected.png'));
9492
const actual = PNG.PNG.sync.read(readFileSync(outputPath));
9593
const {width, height} = expected;
9694
const diff = new PNG.PNG({width, height});
9795

98-
const pixels = pixelmatch(
99-
expected.data,
100-
actual.data,
101-
diff.data,
102-
width,
103-
height,
104-
{threshold: 0.1},
105-
);
96+
const pixels = pixelmatch(expected.data, actual.data, diff.data, width, height, {
97+
threshold: 0.1,
98+
});
10699

107100
expect(pixels).to.equal(0);
108101
});

cirq-web/cirq_ts/src/bloch_sphere/bloch_sphere.ts

Lines changed: 2 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -79,20 +79,12 @@ export class BlochSphere extends Group {
7979
}
8080

8181
private addHorizontalMeridians() {
82-
const meridians = new Meridians(
83-
this.radius,
84-
this.hMeridians,
85-
Orientation.HORIZONTAL,
86-
);
82+
const meridians = new Meridians(this.radius, this.hMeridians, Orientation.HORIZONTAL);
8783
this.add(meridians);
8884
}
8985

9086
private addVerticalMeridians() {
91-
const meridians = new Meridians(
92-
this.radius,
93-
this.vMeridians,
94-
Orientation.VERTICAL,
95-
);
87+
const meridians = new Meridians(this.radius, this.vMeridians, Orientation.VERTICAL);
9688
this.add(meridians);
9789
}
9890

cirq-web/cirq_ts/src/bloch_sphere/bloch_sphere_test.ts

Lines changed: 10 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -39,13 +39,9 @@ describe('BlochSphere (with empty constructor)', () => {
3939
// and then test that it's what we want.
4040
const children = bloch_sphere.children;
4141

42-
const sphere = children.find(
43-
child => child.constructor.name === 'Sphere',
44-
) as Sphere;
42+
const sphere = children.find(child => child.constructor.name === 'Sphere') as Sphere;
4543

46-
const meridians = children.filter(
47-
child => child.constructor.name === 'Meridians',
48-
) as Meridians[];
44+
const meridians = children.filter(child => child.constructor.name === 'Meridians') as Meridians[];
4945

5046
const horizontalMeridians = meridians.find(
5147
child => child.orientation === Orientation.HORIZONTAL,
@@ -55,13 +51,9 @@ describe('BlochSphere (with empty constructor)', () => {
5551
child => child.orientation === Orientation.VERTICAL,
5652
) as Meridians;
5753

58-
const axes = children.find(
59-
child => child.constructor.name === 'Axes',
60-
) as Axes;
54+
const axes = children.find(child => child.constructor.name === 'Axes') as Axes;
6155

62-
const labels = children.find(
63-
child => child.constructor.name === 'Labels',
64-
) as Labels;
56+
const labels = children.find(child => child.constructor.name === 'Labels') as Labels;
6557

6658
it('adds a single BlochSphere of type Group', () => {
6759
const children = scene.children;
@@ -73,9 +65,7 @@ describe('BlochSphere (with empty constructor)', () => {
7365

7466
describe('child group (Sphere, Meridians, etc.)', () => {
7567
it('Sphere contains the correct number of components', () => {
76-
const sphereExists = children.find(
77-
child => child.constructor.name === 'Sphere',
78-
);
68+
const sphereExists = children.find(child => child.constructor.name === 'Sphere');
7969
expect(sphereExists).to.not.equal(undefined);
8070
});
8171

@@ -87,16 +77,12 @@ describe('BlochSphere (with empty constructor)', () => {
8777
});
8878

8979
it('Axes exist', () => {
90-
const axesExists = children.some(
91-
child => child.constructor.name === 'Axes',
92-
);
80+
const axesExists = children.some(child => child.constructor.name === 'Axes');
9381
expect(axesExists).to.equal(true);
9482
});
9583

9684
it('Labels exist', () => {
97-
const labelsExists = children.some(
98-
child => child.constructor.name === 'Labels',
99-
);
85+
const labelsExists = children.some(child => child.constructor.name === 'Labels');
10086
expect(labelsExists).to.equal(true);
10187
});
10288
});
@@ -162,13 +148,9 @@ describe('BlochSphere (with valid custom constructor values)', () => {
162148
const bloch_sphere = new BlochSphere(3, 9, 6);
163149
const children = bloch_sphere.children;
164150

165-
const sphere = children.find(
166-
child => child.constructor.name === 'Sphere',
167-
) as Sphere;
151+
const sphere = children.find(child => child.constructor.name === 'Sphere') as Sphere;
168152

169-
const meridians = children.filter(
170-
child => child.constructor.name === 'Meridians',
171-
) as Meridians[];
153+
const meridians = children.filter(child => child.constructor.name === 'Meridians') as Meridians[];
172154

173155
const horizontalMeridians = meridians.find(
174156
child => child.orientation === Orientation.HORIZONTAL,
@@ -229,8 +211,7 @@ describe('BlochSphere (with valid custom constructor values)', () => {
229211
describe('BlochSphere (with invalid custom constructor values)', () => {
230212
it('fails correctly if given an invalid radius', () => {
231213
const inputs = [0, -1];
232-
const errorMessage =
233-
'The radius of a Sphere must be greater than or equal to 1';
214+
const errorMessage = 'The radius of a Sphere must be greater than or equal to 1';
234215

235216
inputs.forEach(input => {
236217
expect(() => new BlochSphere(input)).to.throw(errorMessage);

cirq-web/cirq_ts/src/bloch_sphere/components/meridians.ts

Lines changed: 6 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -12,13 +12,7 @@
1212
// See the License for the specific language governing permissions and
1313
// limitations under the License.
1414

15-
import {
16-
EllipseCurve,
17-
BufferGeometry,
18-
LineBasicMaterial,
19-
Line,
20-
Group,
21-
} from 'three';
15+
import {EllipseCurve, BufferGeometry, LineBasicMaterial, Line, Group} from 'three';
2216
import {Orientation} from './enums';
2317

2418
interface CurveData {
@@ -87,9 +81,7 @@ export class Meridians extends Group {
8781
}
8882

8983
let nonEquatorCircles: number;
90-
numCircles % 2 !== 0
91-
? (nonEquatorCircles = numCircles - 1)
92-
: (nonEquatorCircles = numCircles);
84+
numCircles % 2 !== 0 ? (nonEquatorCircles = numCircles - 1) : (nonEquatorCircles = numCircles);
9385
const circlesPerHalf = nonEquatorCircles / 2;
9486

9587
// Creates chords proportionally to radius 5 circle.
@@ -98,16 +90,10 @@ export class Meridians extends Group {
9890
// Start building the chords from the top down.
9991
// If the user only wants one chord, skip the loop.
10092
let topmostChordPos: number;
101-
numCircles === 1
102-
? (topmostChordPos = 0)
103-
: (topmostChordPos = radius - initialFactor);
93+
numCircles === 1 ? (topmostChordPos = 0) : (topmostChordPos = radius - initialFactor);
10494

10595
const chordYPositions = [0]; // equator
106-
for (
107-
let i = topmostChordPos;
108-
i > 0;
109-
i -= topmostChordPos / circlesPerHalf
110-
) {
96+
for (let i = topmostChordPos; i > 0; i -= topmostChordPos / circlesPerHalf) {
11197
chordYPositions.push(i);
11298
chordYPositions.push(-i);
11399
}
@@ -154,11 +140,7 @@ export class Meridians extends Group {
154140

155141
for (let i = 0; i < Math.PI; i += Math.PI / numCircles) {
156142
const curve = this.createMeridianCurve(curveData);
157-
const meridianLine = this.createMeridianLine(
158-
curve,
159-
i,
160-
Orientation.VERTICAL,
161-
);
143+
const meridianLine = this.createMeridianLine(curve, i, Orientation.VERTICAL);
162144
this.add(meridianLine);
163145
}
164146
}
@@ -195,10 +177,7 @@ export class Meridians extends Group {
195177
// through the constructor.
196178
}
197179

198-
const meridianLine = new Line(
199-
meridianGeom,
200-
new LineBasicMaterial({color: 'gray'}),
201-
);
180+
const meridianLine = new Line(meridianGeom, new LineBasicMaterial({color: 'gray'}));
202181
if (yPosition) {
203182
meridianLine.position.y = yPosition;
204183
}

cirq-web/cirq_ts/src/bloch_sphere/components/meridians_test.ts

Lines changed: 6 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -25,31 +25,19 @@ describe('Meridians', () => {
2525
describe('by default', () => {
2626
it(`generates the correct number of lines given
2727
the default number (7)`, () => {
28-
const meridians = new Meridians(
29-
DEFAULT_RADIUS,
30-
DEFAULT_H_MERIDIANS,
31-
Orientation.HORIZONTAL,
32-
);
28+
const meridians = new Meridians(DEFAULT_RADIUS, DEFAULT_H_MERIDIANS, Orientation.HORIZONTAL);
3329
expect(meridians.children.length).to.equal(DEFAULT_H_MERIDIANS);
3430
});
3531

3632
it(`generates the correct number of lines given
3733
the default number (4)`, () => {
38-
const meridians = new Meridians(
39-
DEFAULT_RADIUS,
40-
DEFAULT_V_MERIDIANS,
41-
Orientation.VERTICAL,
42-
);
34+
const meridians = new Meridians(DEFAULT_RADIUS, DEFAULT_V_MERIDIANS, Orientation.VERTICAL);
4335
expect(meridians.children.length).to.equal(DEFAULT_V_MERIDIANS);
4436
});
4537

4638
it(`generates lines at the correct positions
4739
with defaults`, () => {
48-
const meridians = new Meridians(
49-
DEFAULT_RADIUS,
50-
DEFAULT_H_MERIDIANS,
51-
Orientation.HORIZONTAL,
52-
);
40+
const meridians = new Meridians(DEFAULT_RADIUS, DEFAULT_H_MERIDIANS, Orientation.HORIZONTAL);
5341

5442
const positions = [
5543
new Vector3(0, 0, 0),
@@ -75,11 +63,7 @@ describe('Meridians', () => {
7563
const lineValues = [4, 0, 17, 299, 4.123, 1];
7664
const expectedLineNumbers = [5, 0, 17, 299, 5, 1];
7765
lineValues.forEach((el, index) => {
78-
const meridians = new Meridians(
79-
DEFAULT_RADIUS,
80-
el,
81-
Orientation.HORIZONTAL,
82-
);
66+
const meridians = new Meridians(DEFAULT_RADIUS, el, Orientation.HORIZONTAL);
8367
expect(meridians.children.length).to.equal(expectedLineNumbers[index]);
8468
});
8569
});
@@ -88,21 +72,13 @@ describe('Meridians', () => {
8872
const lineValues = [4, 0, 17, 299, 4.123];
8973
const expectedLineNumbers = [4, 0, 18, 299, 4];
9074
lineValues.forEach((el, index) => {
91-
const meridians = new Meridians(
92-
DEFAULT_RADIUS,
93-
el,
94-
Orientation.VERTICAL,
95-
);
75+
const meridians = new Meridians(DEFAULT_RADIUS, el, Orientation.VERTICAL);
9676
expect(meridians.children.length).to.equal(expectedLineNumbers[index]);
9777
});
9878
});
9979

10080
it('changes the number of horizontal chord meridians correctly with scale', () => {
101-
const meridians = new Meridians(
102-
DEFAULT_RADIUS,
103-
9,
104-
Orientation.HORIZONTAL,
105-
);
81+
const meridians = new Meridians(DEFAULT_RADIUS, 9, Orientation.HORIZONTAL);
10682

10783
const positions = [
10884
new Vector3(0, 0, 0),

cirq-web/cirq_ts/src/bloch_sphere/components/scene.ts

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -50,10 +50,7 @@ export class BlochSphereScene extends Scene {
5050

5151
this.camera = new PerspectiveCamera(fov, aspect, near, far);
5252
this.renderer = new WebGLRenderer({alpha: true});
53-
this.renderer.setSize(
54-
BlochSphereScene.VIZ_WIDTH,
55-
BlochSphereScene.VIZ_HEIGHT,
56-
);
53+
this.renderer.setSize(BlochSphereScene.VIZ_WIDTH, BlochSphereScene.VIZ_HEIGHT);
5754
this.controls = new OrbitControls(this.camera, this.renderer.domElement);
5855

5956
this.init();

cirq-web/cirq_ts/src/bloch_sphere/components/sphere.ts

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -30,9 +30,7 @@ export class Sphere extends Group {
3030
super();
3131

3232
if (radius < 1) {
33-
throw new Error(
34-
'The radius of a Sphere must be greater than or equal to 1',
35-
);
33+
throw new Error('The radius of a Sphere must be greater than or equal to 1');
3634
} else {
3735
this.radius = radius;
3836
}

cirq-web/cirq_ts/src/bloch_sphere/components/sphere_test.ts

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -68,8 +68,7 @@ describe('Sphere', () => {
6868
describe('throws the correct errors if the user', () => {
6969
it('gives invalid radius inputs (-1, 0)', () => {
7070
const radiusInputs = [-1, 0];
71-
const expectedErrorMessage =
72-
'The radius of a Sphere must be greater than or equal to 1';
71+
const expectedErrorMessage = 'The radius of a Sphere must be greater than or equal to 1';
7372
radiusInputs.forEach(el => {
7473
expect(() => new Sphere(el)).to.throw(expectedErrorMessage);
7574
});

0 commit comments

Comments
 (0)