Skip to content

Commit

Permalink
feat: enable in prettier.config.js (#6)
Browse files Browse the repository at this point in the history
* feat: enable  in prettier.config.js

* feat: enable `trailingComma` in prettier.config.js
  • Loading branch information
YuliaTsareva authored and shoom3301 committed Feb 4, 2019
1 parent 7bb7b82 commit 93a6485
Show file tree
Hide file tree
Showing 8 changed files with 50 additions and 47 deletions.
2 changes: 1 addition & 1 deletion prettier/prettier.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ module.exports = {
useTabs: false,
semi: true,
singleQuote: true,
trailingComma: 'none',
trailingComma: 'all',
bracketSpacing: false,
arrowParens: 'avoid',
overrides: [
Expand Down
22 changes: 11 additions & 11 deletions src/tinkoffAngularMemberOrderingRule.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,8 @@ export class Rule extends Rules.AbstractRule {
'protected-static',
'protected-instance',
'private-static',
'private-instance'
]
'private-instance',
],
},
optionExamples: [
'public-static',
Expand All @@ -31,10 +31,10 @@ export class Rule extends Rules.AbstractRule {
'@Output',
'public-instance',
'protected-instance',
'private-instance'
'private-instance',
],
type: 'style',
typescriptOnly: false
typescriptOnly: false,
};

apply(sourceFile: ts.SourceFile): RuleFailure[] {
Expand All @@ -43,7 +43,7 @@ export class Rule extends Rules.AbstractRule {
const walker = new TinkoffAngularMemberOrderingWalker(
sourceFile,
this.ruleName,
undefined
undefined,
);

return this.applyWithWalker(walker);
Expand All @@ -69,10 +69,10 @@ class TinkoffAngularMemberOrderingWalker extends AngularMemberOrderingWalker {

protected getFailureString(
nextNode: NodeDeclaration,
prevNode: NodeDeclaration
prevNode: NodeDeclaration,
): string {
return `${this.getNodeType(nextNode)} must be before ${this.getNodeType(
prevNode
prevNode,
)}`;
}

Expand Down Expand Up @@ -118,7 +118,7 @@ class TinkoffAngularMemberOrderingWalker extends AngularMemberOrderingWalker {

protected wrongWithAccessor(
node: NodeDeclaration,
prevNode: NodeDeclaration
prevNode: NodeDeclaration,
): boolean {
return (
this.isInputAfterAccessor(node, prevNode) ||
Expand All @@ -128,7 +128,7 @@ class TinkoffAngularMemberOrderingWalker extends AngularMemberOrderingWalker {

private isInputAfterAccessor(
node: NodeDeclaration,
prevNode: NodeDeclaration
prevNode: NodeDeclaration,
): boolean {
const isNodeInput = this.isInput(node);
const isNodeAccessor = this.isInputAccessor(node);
Expand All @@ -139,7 +139,7 @@ class TinkoffAngularMemberOrderingWalker extends AngularMemberOrderingWalker {

private isOutputAfterAccessor(
node: NodeDeclaration,
prevNode: NodeDeclaration
prevNode: NodeDeclaration,
): boolean {
const isNodeOutput = this.isOutput(node);
const isNodeAccessor = this.isOutputAccessor(node);
Expand Down Expand Up @@ -203,7 +203,7 @@ class TinkoffAngularMemberOrderingWalker extends AngularMemberOrderingWalker {
const nodeIsOutput = this.isOutput(node);
const prevNodeIsInput = this.isInput(prevNode);
const nodeStartsWithPrevNode = this.getNodeName(node).startsWith(
this.getNodeName(prevNode)
this.getNodeName(prevNode),
);
const nodeEndsWithChange = this.getNodeName(node).endsWith('Change');

Expand Down
16 changes: 8 additions & 8 deletions src/tinkoffConditionBreaksRule.ts
Original file line number Diff line number Diff line change
Expand Up @@ -112,16 +112,16 @@ class ConditionalBreaksWalker extends Lint.RuleWalker {
private static getFixes(node: ts.ConditionalExpression): Replacement[] {
const lineAndChar = ts.getLineAndCharacterOfPosition(
node.getSourceFile(),
node.getStart()
node.getStart(),
);
const lineStartPosition = ts.getPositionOfLineAndCharacter(
node.getSourceFile(),
lineAndChar.line,
0
0,
);
const whitespaces = ConditionalBreaksWalker.getWhitespaces(
node.getSourceFile().text,
lineStartPosition
lineStartPosition,
);

return [
Expand All @@ -130,23 +130,23 @@ class ConditionalBreaksWalker extends Lint.RuleWalker {
node.questionToken.getFullWidth(),
node.questionToken
.getFullText()
.replace(/\s*\?/, '\n' + whitespaces + '?')
.replace(/\s*\?/, '\n' + whitespaces + '?'),
),
new Replacement(
node.colonToken.getFullStart(),
node.colonToken.getFullWidth(),
node.colonToken.getFullText().replace(/\s*:/, '\n' + whitespaces + ':')
node.colonToken.getFullText().replace(/\s*:/, '\n' + whitespaces + ':'),
),
new Replacement(
node.whenTrue.getFullStart(),
node.whenTrue.getFullWidth(),
node.whenTrue.getFullText().replace(/^\s*/, ' ')
node.whenTrue.getFullText().replace(/^\s*/, ' '),
),
new Replacement(
node.whenFalse.getFullStart(),
node.whenFalse.getFullWidth(),
node.whenFalse.getFullText().replace(/^\s*/, ' ')
)
node.whenFalse.getFullText().replace(/^\s*/, ' '),
),
];
}

Expand Down
2 changes: 1 addition & 1 deletion src/tinkoffMethodReturnTypeRule.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ class TinkoffMethodReturnTypeWalker extends Lint.RuleWalker {
this.addFailureAt(
this.findClosingBracket(methodNode).getEnd(),
1,
Rule.FAILURE_STRING
Rule.FAILURE_STRING,
);
}
}
Expand Down
4 changes: 2 additions & 2 deletions src/tinkoffNewLineAfterVariableDeclarationRule.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,14 +13,14 @@ export class Rule extends Rules.AbstractRule {
options: {},
optionExamples: [],
type: 'style',
typescriptOnly: false
typescriptOnly: false,
};

apply(sourceFile: ts.SourceFile): RuleFailure[] {
const walker = new TinkoffNewLineAfterVariableDeclarationWalker(
sourceFile,
this.ruleName,
undefined
undefined,
);

return this.applyWithWalker(walker);
Expand Down
4 changes: 2 additions & 2 deletions src/tinkoffNewLineAroundControlStatementRule.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,14 +14,14 @@ export class Rule extends Lint.Rules.AbstractRule {
options: {},
optionExamples: [],
type: 'style',
typescriptOnly: false
typescriptOnly: false,
};

apply(sourceFile: ts.SourceFile): Lint.RuleFailure[] {
const walker = new NewlineAroundControlStatementWalker(
sourceFile,
this.ruleName,
undefined
undefined,
);

return this.applyWithWalker(walker);
Expand Down
42 changes: 21 additions & 21 deletions src/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ export function getLeadingWhitespace(node: ts.Node, sourceFile: ts.SourceFile):

export function getTrailingWhitespace(
node: ts.Statement,
sourceFile: ts.SourceFile
sourceFile: ts.SourceFile,
): string {
const next = getNextStatement(node);
const fromLine = ts.getLineAndCharacterOfPosition(sourceFile, next.getStart()).line;
Expand All @@ -23,7 +23,7 @@ function getWhitespace(sourceFile: ts.SourceFile, fromLine: number): string {
ts.ScriptTarget.ES5,
false,
ts.LanguageVariant.Standard,
sourceFile.text
sourceFile.text,
);

whitespaceScanner.setTextPos(sourceFile.getLineStarts()[fromLine]);
Expand Down Expand Up @@ -72,7 +72,7 @@ export abstract class NewLineRuleWalker extends AbstractWalker<void> {
for (let i = comments.length - 1; i >= 0; --i) {
const endLine = ts.getLineAndCharacterOfPosition(
this.sourceFile,
comments[i].end
comments[i].end,
).line;

if (endLine < line - 1) {
Expand All @@ -91,13 +91,13 @@ export abstract class NewLineRuleWalker extends AbstractWalker<void> {
const replacement = new Replacement(
prev.getEnd(),
start - prev.getEnd(),
`\n\n${whitespace}`
`\n\n${whitespace}`,
);

this.addFailureAtNode(
node.getFirstToken(),
this.getFailureString(),
replacement
replacement,
);
}
}
Expand All @@ -122,7 +122,7 @@ export abstract class NewLineRuleWalker extends AbstractWalker<void> {
for (let i = comments.length - 1; i >= 0; --i) {
const startLine = ts.getLineAndCharacterOfPosition(
this.sourceFile,
comments[i].pos
comments[i].pos,
).line;

if (startLine === line && comments[i].end < next.getStart()) {
Expand All @@ -143,7 +143,7 @@ export abstract class NewLineRuleWalker extends AbstractWalker<void> {
this.addFailureAtNode(
node.getLastToken(),
this.getFailureString(),
replacement
replacement,
);
}
}
Expand All @@ -166,36 +166,36 @@ export abstract class NewLineRuleWalker extends AbstractWalker<void> {
export const defaultMemberData = {
'public-static': {
rank: 0,
text: 'PUBLIC STATIC property'
text: 'PUBLIC STATIC property',
},
'protected-static': {
rank: 1,
text: 'PROTECTED STATIC property'
text: 'PROTECTED STATIC property',
},
'private-static': {
rank: 2,
text: 'PRIVATE STATIC property'
text: 'PRIVATE STATIC property',
},
'@Input': {
rank: 3,
text: '@Input'
text: '@Input',
},
'@Output': {
rank: 4,
text: '@Output'
text: '@Output',
},
'public-instance': {
rank: 5,
text: 'PUBLIC INSTANCE property'
text: 'PUBLIC INSTANCE property',
},
'protected-instance': {
rank: 6,
text: 'PROTECTED INSTANCE property'
text: 'PROTECTED INSTANCE property',
},
'private-instance': {
rank: 7,
text: 'PRIVATE INSTANCE property'
}
text: 'PRIVATE INSTANCE property',
},
};

type NodeDeclaration =
Expand All @@ -217,13 +217,13 @@ export abstract class AngularMemberOrderingWalker extends AbstractWalker<IOption
this.addFailureAt(
node.getStart(),
this.nodeWidth(node),
this.getFailureString(node, this.lastPropertyDeclaration)
this.getFailureString(node, this.lastPropertyDeclaration),
);
} else if (this.wrongWithAccessor(node, this.lastPropertyDeclaration)) {
this.addFailureAt(
this.lastPropertyDeclaration.getStart(),
this.nodeWidth(this.lastPropertyDeclaration),
this.getFailureStringForAccessor(this.lastPropertyDeclaration)
this.getFailureStringForAccessor(this.lastPropertyDeclaration),
);
}

Expand All @@ -248,18 +248,18 @@ export abstract class AngularMemberOrderingWalker extends AbstractWalker<IOption

protected abstract getFailureString(
nextNode: NodeDeclaration,
prevNode: NodeDeclaration
prevNode: NodeDeclaration,
): string;
protected abstract getFailureStringForAccessor(node: NodeDeclaration): string;
protected abstract hasMatch(node: ts.Node): boolean;
protected abstract isRightOrder(
node: NodeDeclaration,
prevNode: NodeDeclaration
prevNode: NodeDeclaration,
): boolean;
protected abstract isClass(node: ts.Node): boolean;
protected abstract nodeWidth(node: NodeDeclaration): number;
protected abstract wrongWithAccessor(
node: NodeDeclaration,
prevNode: NodeDeclaration
prevNode: NodeDeclaration,
): boolean;
}
5 changes: 4 additions & 1 deletion tslint/bases/prettier.tslint.json
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
{
"extends": ["./base.tslint.json"]
"extends": ["./base.tslint.json"],
"rules": {
"trailing-comma": false
}
}

0 comments on commit 93a6485

Please sign in to comment.