Skip to content

Commit 00e29c2

Browse files
committed
Revert "test: angular-whitespace with interpolation (#494)"
This reverts commit 97970d2.
1 parent 97970d2 commit 00e29c2

File tree

3 files changed

+28
-145
lines changed

3 files changed

+28
-145
lines changed

test/angularWhitespaceRule.spec.ts

Lines changed: 23 additions & 134 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,10 @@
1-
import { assertSuccess, assertAnnotated, assertMultipleAnnotated, assertFailure, assertFailures } from './testHelper';
1+
import { assertSuccess, assertAnnotated, assertMultipleAnnotated } from './testHelper';
22
import { Replacement } from 'tslint';
33
import { expect } from 'chai';
44
import { FsFileResolver } from '../src/angular/fileResolver/fsFileResolver';
55
import { MetadataReader } from '../src/angular/metadataReader';
66
import * as ts from 'typescript';
77
import chai = require('chai');
8-
import { readFileSync } from 'fs';
98

109
const getAst = (code: string, file = 'file.ts') => {
1110
return ts.createSourceFile(file, code, ts.ScriptTarget.ES5, true);
@@ -119,6 +118,7 @@ describe('angular-whitespace', () => {
119118
})
120119
class Bar {}
121120
`;
121+
const reader = new MetadataReader(new FsFileResolver());
122122
const ast = getAst(code, __dirname + '/../../test/fixtures/angularWhitespace/component.ts');
123123
assertSuccess('angular-whitespace', ast, ['check-pipe']);
124124
});
@@ -167,6 +167,7 @@ describe('angular-whitespace', () => {
167167
ponies = []
168168
}
169169
`;
170+
const reader = new MetadataReader(new FsFileResolver());
170171
const ast = getAst(code, __dirname + '/../../test/fixtures/angularWhitespace/component.ts');
171172
assertSuccess('angular-whitespace', ast, ['check-pipe']);
172173
});
@@ -306,8 +307,8 @@ describe('failure', () => {
306307
assertMultipleAnnotated({
307308
ruleName: 'angular-whitespace',
308309
failures: [
309-
{ char: '~', msg: 'Missing whitespace in interpolation start; expecting {{ expr }}', },
310-
{ char: '^', msg: 'Missing whitespace in interpolation end; expecting {{ expr }}', },
310+
{char: '~', msg: 'Missing whitespace in interpolation start; expecting {{ expr }}', },
311+
{char: '^', msg: 'Missing whitespace in interpolation end; expecting {{ expr }}', },
311312
],
312313
source,
313314
options: ['check-interpolation']
@@ -345,8 +346,8 @@ describe('failure', () => {
345346
const failures = assertMultipleAnnotated({
346347
ruleName: 'angular-whitespace',
347348
failures: [
348-
{ char: '~', msg: 'Missing whitespace in interpolation start; expecting {{ expr }}', },
349-
{ char: '^', msg: 'Missing whitespace in interpolation end; expecting {{ expr }}', },
349+
{char: '~', msg: 'Missing whitespace in interpolation start; expecting {{ expr }}', },
350+
{char: '^', msg: 'Missing whitespace in interpolation end; expecting {{ expr }}', },
350351
],
351352
source,
352353
options: ['check-interpolation']
@@ -378,8 +379,8 @@ describe('failure', () => {
378379
const failures = assertMultipleAnnotated({
379380
ruleName: 'angular-whitespace',
380381
failures: [
381-
{ char: '~', msg: 'Missing whitespace in interpolation start; expecting {{ expr }}', },
382-
{ char: '^', msg: 'Missing whitespace in interpolation end; expecting {{ expr }}', },
382+
{char: '~', msg: 'Missing whitespace in interpolation start; expecting {{ expr }}', },
383+
{char: '^', msg: 'Missing whitespace in interpolation end; expecting {{ expr }}', },
383384
],
384385
source,
385386
options: ['check-interpolation']
@@ -399,118 +400,6 @@ describe('failure', () => {
399400
class Bar {}`);
400401
});
401402

402-
it('should fail and apply proper replacements when style is incorrect', () => {
403-
let source = `
404-
@Component({
405-
template: \`
406-
<h1>
407-
{{foo}}
408-
~~ ^^
409-
</h1>
410-
\`
411-
})
412-
class Bar {}`;
413-
const failures = assertMultipleAnnotated({
414-
ruleName: 'angular-whitespace',
415-
failures: [
416-
{ char: '~', msg: 'Missing whitespace in interpolation start; expecting {{ expr }}', },
417-
{ char: '^', msg: 'Missing whitespace in interpolation end; expecting {{ expr }}', },
418-
],
419-
source,
420-
options: ['check-interpolation']
421-
});
422-
423-
const res = Replacement.applyAll(source, [].concat.apply([], failures.map(f => f.getFix())));
424-
expect(res).to.eq(`
425-
@Component({
426-
template: \`
427-
<h1>
428-
{{ foo }}
429-
~~ ^^
430-
</h1>
431-
\`
432-
})
433-
class Bar {}`);
434-
});
435-
436-
it('should fail and apply proper replacements when style is incorrect', () => {
437-
let source = `
438-
@Component({
439-
template: \`
440-
<div>
441-
{{message.ACTIVATED}}
442-
~~ ^^
443-
</div>
444-
\`
445-
})
446-
class Bar {}`;
447-
const failures = assertMultipleAnnotated({
448-
ruleName: 'angular-whitespace',
449-
failures: [
450-
{ char: '~', msg: 'Missing whitespace in interpolation start; expecting {{ expr }}', },
451-
{ char: '^', msg: 'Missing whitespace in interpolation end; expecting {{ expr }}', },
452-
],
453-
source,
454-
options: ['check-interpolation']
455-
});
456-
457-
const res = Replacement.applyAll(source, [].concat.apply([], failures.map(f => f.getFix())));
458-
expect(res).to.eq(`
459-
@Component({
460-
template: \`
461-
<div>
462-
{{ message.ACTIVATED }}
463-
~~ ^^
464-
</div>
465-
\`
466-
})
467-
class Bar {}`);
468-
});
469-
470-
it('should work with external templates with interpolation', () => {
471-
const code = `
472-
@Component({
473-
selector: 'foo',
474-
moduleId: module.id,
475-
templateUrl: 'interpolation.html',
476-
})
477-
class Bar {
478-
ponies = []
479-
}
480-
`;
481-
const ast = getAst(code, __dirname + '/../../test/fixtures/angularWhitespace/component.ts');
482-
const failures = assertFailures('angular-whitespace', ast, [{
483-
message: 'Missing whitespace in interpolation start; expecting {{ expr }}',
484-
startPosition: {
485-
line: 2,
486-
character: 3
487-
},
488-
endPosition: {
489-
line: 2,
490-
character: 5
491-
}
492-
}, {
493-
message: 'Missing whitespace in interpolation end; expecting {{ expr }}',
494-
startPosition: {
495-
line: 2,
496-
character: 22
497-
},
498-
endPosition: {
499-
line: 2,
500-
character: 24
501-
}
502-
}
503-
], ['check-interpolation']);
504-
const template = readFileSync(__dirname + '/../../test/fixtures/angularWhitespace/interpolation.html').toString();
505-
const res = Replacement.applyAll(template, [].concat.apply([], failures.map(f => f.getFix())));
506-
expect(res).to.equal(`<div class="account-product__sub-title">
507-
<div *ngIf="productIsFixed">
508-
{{ message.ACTIVATED }}
509-
</div>
510-
</div>
511-
`);
512-
});
513-
514403
it('should fail and apply proper replacements when style is incorrect with multiple failures', () => {
515404
let source = `
516405
@Component({
@@ -529,10 +418,10 @@ describe('failure', () => {
529418
const failures = assertMultipleAnnotated({
530419
ruleName: 'angular-whitespace',
531420
failures: [
532-
{ char: '~', msg: 'Missing whitespace in interpolation start; expecting {{ expr }}', },
533-
{ char: '-', msg: 'Missing whitespace in interpolation end; expecting {{ expr }}', },
534-
{ char: '^', msg: 'Extra whitespace in interpolation start; expecting {{ expr }}', },
535-
{ char: '#', msg: 'Extra whitespace in interpolation end; expecting {{ expr }}', },
421+
{char: '~', msg: 'Missing whitespace in interpolation start; expecting {{ expr }}', },
422+
{char: '-', msg: 'Missing whitespace in interpolation end; expecting {{ expr }}', },
423+
{char: '^', msg: 'Extra whitespace in interpolation start; expecting {{ expr }}', },
424+
{char: '#', msg: 'Extra whitespace in interpolation end; expecting {{ expr }}', },
536425
],
537426
source,
538427
options: ['check-interpolation']
@@ -594,8 +483,8 @@ describe('failure', () => {
594483
const failures = assertMultipleAnnotated({
595484
ruleName: 'angular-whitespace',
596485
failures: [
597-
{ char: '~', msg: 'Extra whitespace in interpolation start; expecting {{ expr }}', },
598-
{ char: '^', msg: 'Extra whitespace in interpolation end; expecting {{ expr }}', },
486+
{char: '~', msg: 'Extra whitespace in interpolation start; expecting {{ expr }}', },
487+
{char: '^', msg: 'Extra whitespace in interpolation end; expecting {{ expr }}', },
599488
],
600489
source,
601490
options: ['check-interpolation']
@@ -778,8 +667,8 @@ describe('failure', () => {
778667
const failures = assertMultipleAnnotated({
779668
ruleName: 'angular-whitespace',
780669
failures: [
781-
{ char: '~', msg: 'Missing whitespace after semicolon; expecting \'; expr\'', },
782-
{ char: '^', msg: 'Missing whitespace after semicolon; expecting \'; expr\'', },
670+
{char: '~', msg: 'Missing whitespace after semicolon; expecting \'; expr\'', },
671+
{char: '^', msg: 'Missing whitespace after semicolon; expecting \'; expr\'', },
783672
],
784673
source,
785674
options: ['check-semicolon']
@@ -808,8 +697,8 @@ describe('failure', () => {
808697
const failures = assertMultipleAnnotated({
809698
ruleName: 'angular-whitespace',
810699
failures: [
811-
{ char: '~', msg: 'Missing whitespace after semicolon; expecting \'; expr\'', },
812-
{ char: '^', msg: 'Missing whitespace after semicolon; expecting \'; expr\'', },
700+
{char: '~', msg: 'Missing whitespace after semicolon; expecting \'; expr\'', },
701+
{char: '^', msg: 'Missing whitespace after semicolon; expecting \'; expr\'', },
813702
],
814703
source,
815704
options: ['check-semicolon']
@@ -1041,8 +930,8 @@ describe('pipes', () => {
1041930
const failures = assertMultipleAnnotated({
1042931
ruleName: 'angular-whitespace',
1043932
failures: [
1044-
{ char: '~', msg: 'The pipe operator should be surrounded by one space on each side, i.e. " | ".', },
1045-
{ char: '^', msg: 'The pipe operator should be surrounded by one space on each side, i.e. " | ".', },
933+
{char: '~', msg: 'The pipe operator should be surrounded by one space on each side, i.e. " | ".', },
934+
{char: '^', msg: 'The pipe operator should be surrounded by one space on each side, i.e. " | ".', },
1046935
],
1047936
source,
1048937
options: ['check-pipe']
@@ -1167,8 +1056,8 @@ describe('angular-whitespace multiple checks', () => {
11671056
const failures = assertMultipleAnnotated({
11681057
ruleName: 'angular-whitespace',
11691058
failures: [
1170-
{ char: '~', msg: 'Missing whitespace in interpolation start; expecting {{ expr }}', },
1171-
{ char: '^', msg: 'The pipe operator should be surrounded by one space on each side, i.e. " | ".', },
1059+
{char: '~', msg: 'Missing whitespace in interpolation start; expecting {{ expr }}', },
1060+
{char: '^', msg: 'The pipe operator should be surrounded by one space on each side, i.e. " | ".', },
11721061
],
11731062
source,
11741063
options: ['check-interpolation', 'check-pipe']

test/fixtures/angularWhitespace/interpolation.html

Lines changed: 0 additions & 5 deletions
This file was deleted.

test/testHelper.ts

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,7 @@ export interface AssertMultipleConfigs {
8181
ruleName: string;
8282
source: string;
8383
options?: any;
84-
failures: { char: string; msg: string }[];
84+
failures: {char: string; msg: string}[];
8585
}
8686

8787
/**
@@ -205,8 +205,8 @@ export function assertMultipleAnnotated(configs: AssertMultipleConfigs): Lint.Ru
205205
* This is 0-based index of the error that will be tested for. 0 by default.
206206
* @returns {any}
207207
*/
208-
export function assertFailure(ruleName: string, source: string | ts.SourceFile, fail: IExpectedFailure,
209-
options = null, onlyNthFailure: number = 0): Lint.RuleFailure[] {
208+
export function assertFailure(ruleName: string, source: string, fail: IExpectedFailure,
209+
options = null, onlyNthFailure: number = 0): Lint.RuleFailure[] {
210210
let result: Lint.LintResult;
211211
try {
212212
result = lint(ruleName, source, options);
@@ -233,8 +233,8 @@ export function assertFailure(ruleName: string, source: string | ts.SourceFile,
233233
* @param fails
234234
* @param options
235235
*/
236-
export function assertFailures(ruleName: string, source: string | ts.SourceFile, fails: IExpectedFailure[], options = null) {
237-
let result: tslint.LintResult;
236+
export function assertFailures(ruleName: string, source: string, fails: IExpectedFailure[], options = null) {
237+
let result;
238238
try {
239239
result = lint(ruleName, source, options);
240240
} catch (e) {
@@ -246,7 +246,6 @@ export function assertFailures(ruleName: string, source: string | ts.SourceFile,
246246
chai.assert.deepEqual(fails[index].startPosition, ruleFail.getStartPosition().getLineAndCharacter(), 'start char doesn\'t match');
247247
chai.assert.deepEqual(fails[index].endPosition, ruleFail.getEndPosition().getLineAndCharacter(), 'end char doesn\'t match');
248248
});
249-
return result.failures;
250249
}
251250

252251
/**

0 commit comments

Comments
 (0)