This file contains hidden or 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
| var getCSSSelector = function () { | |
| var path, node = this; | |
| while (node.length) { | |
| var realNode = node[0], name = realNode.localName; | |
| if (!name) break; | |
| name = name.toLowerCase(); | |
| var parent = node.parent(); | |
| var sameTagSiblings = parent.children(name); | |
| if (sameTagSiblings.length > 1) { |
This file contains hidden or 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
| var esprima = require('esprima'); | |
| var esquery = require('esquery'); | |
| var ast = esprima.parse('function hello () { }'); | |
| var func = esquery(ast, 'FunctionDeclaration'); | |
| console.log(ast.body[0] === func); // false; |
This file contains hidden or 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
| if (navigator.getBattery) { | |
| navigator.getBattery().then((battery) => { | |
| if (battery && battery.level < 0.2) { | |
| let disableAnimations = document.createElement('style'); | |
| disableAnimations.type = 'text/css'; | |
| disableAnimations.innerHTML = ` | |
| * { | |
| transition-property: none !important; | |
| animation: none !important; | |
| } |
This file contains hidden or 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
| var oldCreateElement = document.createElement; | |
| document.createElement = function () { | |
| var tagName = arguments[0]; | |
| var element = oldCreateElement.apply(document, arguments); | |
| if (tagName === 'script') { | |
| element.setAttribute('defer', ''); | |
| } | |
| return element; | |
| }; |
This file contains hidden or 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
| // Test Utilities: | |
| import { ast, expect } from './index'; | |
| // Under test: | |
| import { Rule } from '../src/noTypeofBrowserGlobalRule'; | |
| describe('no-typeof-browser-global', () => { | |
| it('should fail when `typeof` is used to check for "document"', () => { | |
| const sourceFile = ast(` | |
| typeof document === 'undefined'; |
This file contains hidden or 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
| // Dependencies: | |
| import { tsquery } from '@phenomnomnominal/tsquery'; | |
| import { Fix, Replacement, RuleFailure, Rules } from 'tslint'; | |
| import { SourceFile } from 'typescript'; | |
| // Constants: | |
| const FDESCRIBE_FIT_QUERY = 'CallExpression > Identifier[name=/^f(describe|it)$/]'; | |
| const FAILURE_MESSAGE = (filter: string) => ` |
This file contains hidden or 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
| // Dependencies: | |
| import { RuleFailure, Rules } from 'tslint'; | |
| import { SourceFile } from 'typescript'; | |
| export class Rule extends Rules.AbstractRule { | |
| public apply (sourceFile: SourceFile): Array<RuleFailure> { | |
| } | |
| } |
This file contains hidden or 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
| // Dependencies: | |
| import { RuleFailure, Rules } from 'tslint'; | |
| import { SourceFile } from 'typescript'; | |
| export class Rule extends Rules.AbstractRule { | |
| public apply (sourceFile: SourceFile): Array<RuleFailure> { | |
| return this.applyWithWalker(new MyCustomRuleWalker(sourceFile)); | |
| } | |
| } |
This file contains hidden or 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 { AbstractWalker } from 'tslint'; | |
| import { forEachChild, Node, SourceFile } from 'typescript'; | |
| class NoFDescribeOrFItWalker extends AbstractWalker { | |
| public walk (sourceFile: SourceFile) { | |
| const walkNode = (node: Node): void => { | |
| // ... | |
| // evaluate rule | |
| // ... | |
| return forEachChild(node, walkNode); |
This file contains hidden or 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 { AbstractWalker } from 'tslint'; | |
| import { forEachChild, Node, SourceFile, SyntaxKind } from 'typescript'; | |
| class NoFDescribeOrFItWalker extends AbstractWalker { | |
| public walk (sourceFile: SourceFile) { | |
| const walkNode = (node: Node): void => { | |
| if (node.kind === SyntaxKind.CallExpression) { | |
| if (node.expression.kind === SyntaxKind.Identifier) { | |
| // possible rule match! | |
| } |
OlderNewer