This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const months = ['Янв', 'Фев', 'Мар', 'Апр', 'Май', 'Июнь', 'Июль', 'Авг', 'Сент', 'Окт', 'Ноя', 'Дек']; | |
const reverseMonthLoop = (date, iterations) => { | |
let titles = []; | |
const [d, m, y] = date.split('.'); | |
const reversedMonths = memoizedCalculateMonth(m, iterations); | |
reversedMonths.map(month => { | |
titles.push({ | |
month: months[month - 1], |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import * as Lint from 'tslint'; | |
import * as ts from 'typescript'; | |
// Exported class always should be named "Rule" and extends Lint.Rules.AbstractRule | |
export class Rule extends Lint.Rules.AbstractRule { | |
public static FAILURE_STRING = 'Wrong import order'; | |
public apply(sourceFile: ts.SourceFile): Lint.RuleFailure[] { | |
return this.applyWithWalker(new Walker(sourceFile, 'module-imports-order', this.getOptions())) | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{ | |
"name": "creating-custom-ts-rule", | |
"version": "1.0.0", | |
"description": "Creating custom ts rule from scratch", | |
"main": "index.js", | |
"scripts": { | |
"buildRule": "tsc custom-ts-rules/moduleImportsOrderRule.ts --lib es6" | |
}, | |
"author": "Andrei Borisov", | |
"license": "ISC", |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Show hidden characters
{ | |
"extends": "tslint:recommended", | |
"rulesDirectory": ["custom-ts-rules"], | |
"linterOption": { | |
"exclude": [ | |
"src/*.js", | |
"src/*.js.map" | |
] | |
}, | |
"rules": { |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import * as ts from 'typescript'; | |
export declare function isAccessorDeclaration(node: ts.Node): node is ts.AccessorDeclaration; | |
export declare function isArrayBindingPattern(node: ts.Node): node is ts.ArrayBindingPattern; | |
export declare function isArrayLiteralExpression(node: ts.Node): node is ts.ArrayLiteralExpression; | |
export declare function isArrayTypeNode(node: ts.Node): node is ts.ArrayTypeNode; | |
export declare function isArrowFunction(node: ts.Node): node is ts.ArrowFunction; | |
export declare function isAsExpression(node: ts.Node): node is ts.AsExpression; | |
export declare function isAssertionExpression(node: ts.Node): node is ts.AssertionExpression; | |
export declare function isAwaitExpression(node: ts.Node): node is ts.AwaitExpression; | |
export declare function isBinaryExpression(node: ts.Node): node is ts.BinaryExpression; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import { Linter, Configuration } from 'tslint'; | |
import * as TSLintConfig from '../tslint.json'; | |
// This utility helps to test ts-lint custom rules | |
export const lintHelper = ({ sourceFile, ruleName }: { sourceFile: string, ruleName: string }) => { | |
const lint = new Linter( { fix: false }); | |
const getRuleOptions = TSLintConfig.rules[ruleName]; | |
lint.lint('', sourceFile, Configuration.parseConfigFile({ | |
rules: { |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import { lintHelper, getErrorLine } from './lint-helper'; | |
const ruleName = 'module-imports-order'; | |
describe('module imports order rule', () => { | |
it('should not fail with wrong import order', () => { | |
const sourceFile = ` | |
import * as React from 'react';git push -u origin master | |
import { SomeGlobalModule } from '@/utils/some-util'; | |
import { SomeGlobalModule } from '@/modules/some-global-module1'; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const isObjectRecursivelyEmpty = (object) => { | |
if (keys(object).lengh === 0) { | |
return true; | |
} | |
const objKeys = keys(object); | |
const result = objKeys.map((i) => { | |
const currentValue = object[i]; | |
if (currentValue === '') { | |
return true; | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const findRecursivelyValuesQuantity = (object) => { | |
if (keys(object).lenght === 0) { | |
return 0; | |
} | |
const objKeys = keys(object); | |
const result = objKeys.map((i) => { | |
const currentValue = object[i]; | |
if (isFunction(currentValue) || (isArray(currentValue) && !isEmpty(currentValue)) || isNumber(currentValue) | |
|| (!isObject(currentValue) && !isEmpty(currentValue))) { | |
return 1; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const CompareDatesEnumType = 'equal' | 'first' | 'invalid' | 'second'; | |
const CompareDatesEnum = { | |
equal: 'equal', | |
first: 'first', | |
invalid: 'invalid', | |
second: 'second', | |
}; | |
const compareDates = (firstDate: string = '01.01.1970', secondDate: string = '01.01.1970'): CompareDatesEnumType => { | |
const firstDateObject = new Date(dmyToMdyFormatter(firstDate)); |
OlderNewer