Skip to content
This repository has been archived by the owner on Mar 13, 2018. It is now read-only.

Migrating to Typescript #121

Open
wants to merge 13 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
5 changes: 4 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
node_modules
bower_components
*~
typings
lib
*~
*.log
26 changes: 26 additions & 0 deletions custom_typings/command-line-args.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
declare module "command-line-args" {
interface ArgDescriptor {
name: string;
// type: Object;
alias?: string;
description: string;
defaultValue?: any;
defaultOption?: boolean;
type: (val: string) => any;
multiple?: boolean;
}
interface UsageOpts {
title: string;
header?: string;
description?: string;
}
interface CLI {
parse(): any;
getUsage(opts: UsageOpts): string;
}

function commandLineArgs(args: ArgDescriptor[]): CLI;
namespace commandLineArgs {}

export = commandLineArgs;
}
64 changes: 64 additions & 0 deletions custom_typings/dom5.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
declare module 'dom5' {
export interface Node {
nodeName: string;
tagName: string;
childNodes: Node[];
parentNode: Node;
attrs: Attr[];
value?: string;
data?: string;
__location?: {
start: number;
}
}
export interface Attr {
name: string;
value: string;
}
interface ParseOptions {
locationInfo: boolean;
}

export function parse(text: string, opts?: ParseOptions):Node;
export function parseFragment(text: string, opts?: ParseOptions):Node;

export function serialize(node: Node): string;

export type Predicate = (n:Node) => boolean;
export function query(root: Node, predicate: Predicate):Node;
export function queryAll(root: Node, predicate: Predicate):Node[];
export function nodeWalk(node: Node, predicate: Predicate):Node;
export function nodeWalkAll(node: Node, predicate: Predicate):Node[];
export function nodeWalkAllPrior(node: Node, predicate: Predicate):Node[];
export function nodeWalkPrior(node: Node, predicate: Predicate): Node;
export function treeMap(node: Node, walker:(node: Node)=>void):void;
export function getAttribute(node: Node, attrName: string): string;
export function removeAttribute(node: Node, attrName: string): string;
export function getTextContent(node: Node): string;
export function setTextContent(node: Node, string: string): void;
export function append(parent: Node, newNode: Node): void;
export function remove(willBeRemoved: Node): void;
export function replace(current: Node, replacement: Node): void;
export function isTextNode(node: Node): boolean;


export var isCommentNode: Predicate;
interface PredicateCombinators {
hasTagName(name: string):Predicate;
hasAttr(name: string): Predicate;
hasAttrValue(name: string, value: string): Predicate;
parentMatches(predicateFn: Predicate): Predicate;
hasTextValue(value:string): Predicate;
hasMatchingTagName(regex:RegExp): boolean;
NOT(pred: Predicate):Predicate;
AND(...preds: Predicate[]):Predicate;
OR(...preds: Predicate[]):Predicate;
}
export var predicates: PredicateCombinators;

interface Constructors {
element(tagName: string): Node;
text(content: string): Node;
}
export var constructors: Constructors;
}
22 changes: 22 additions & 0 deletions custom_typings/hydrolysis.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
declare module "hydrolysis" {
interface Options {
filter?: (path: string) => boolean;
}
interface Element {
is: string;
contentHref: string;
desc?: string;
}
interface Behavior {
is: string;
contentHref: string;
desc?: string;
}
export class Analyzer {
static analyze(path: string, options: Options): Promise<Analyzer>;
metadataTree(path: string): Promise<void>;
annotate(): void;
elements: Element[];
behaviors: Behavior[];
}
}
49 changes: 0 additions & 49 deletions lib/case-map.js

This file was deleted.

9 changes: 5 additions & 4 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,10 @@
"name": "polylint",
"version": "2.10.1",
"description": "Keeps your Polymer Elements clean and functional!",
"main": "polylint.js",
"bin": "bin/polylint.js",
"main": "lib/polylint.js",
"bin": "lib/polylint-bin.js",
"scripts": {
"test": "bower install && node_modules/.bin/jshint polylint.js bin lib test && node_modules/.bin/mocha test/test.js"
"test": "bower install && node_modules/.bin/jshint test && node_modules/.bin/mocha test/test.js"
},
"repository": {
"type": "git",
Expand All @@ -30,6 +30,7 @@
"bower": "^1.6.5",
"chai": "^2.3.0",
"jshint": "^2.7.0",
"mocha": "^2.2.4"
"mocha": "^2.2.4",
"typings": "^0.8.1"
}
}
41 changes: 18 additions & 23 deletions lib/cli.js → src/cli.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
#!/usr/bin/env node
/**
* @license
* Copyright (c) 2015 The Polymer Project Authors. All rights reserved.
Expand All @@ -9,19 +8,24 @@
* subject to an additional IP rights grant found at http://polymer.github.io/PATENTS.txt
*/
// jshint node:true
// jshint esversion: 6
'use strict';
var polylint = require('../polylint');
var jsconf_policy = require('../lib/jsconf-policy');
import {polylint} from './polylint';
import * as jsconf_policy from './jsconf-policy';
import * as cliArgs from "command-line-args";
import * as fs from 'fs';
import * as path from 'path';
import pathIsAbsolute = require('path-is-absolute');

//Trying to import this the TS leads to some really strange errors
var colors = require('colors/safe');
var cliArgs = require("command-line-args");
var fs = require('fs');
var pathIsAbsolute = require('path-is-absolute');
var path = require('path');


// jshint -W079
var Promise = global.Promise || require('es6-promise').Promise;
//var Promise = global.Promise || require('es6-promise').Promise;
// jshint +W079

var argumentDefinitions = [
const cli = cliArgs([
{
name: "help",
type: Boolean,
Expand Down Expand Up @@ -107,16 +111,14 @@ var argumentDefinitions = [
"Only report errors on specified input files, not from their dependencies."
)
}
];

var cli = cliArgs(argumentDefinitions);
]);

var usage = cli.getUsage({
header: "polylint checks Polymer apps for problematic code patterns",
title: "polylint"
});

function run(env, args, stdout) {
export function run(env, args, stdout) {
return new Promise(function(resolve, reject) {
var options = cli.parse();

Expand All @@ -129,7 +131,7 @@ function run(env, args, stdout) {
});
}

function runWithOptions(options) {
export function runWithOptions(options) {
return new Promise(function(resolve, reject) {
// Check options and dump usage if we find problems.
var inputsOk = true;
Expand All @@ -141,7 +143,7 @@ function runWithOptions(options) {
if (options['config-file'] && options['config-field']) {
var field = options['config-field'];
try {
var contents = fs.readFileSync(options['config-file']);
var contents:any = fs.readFileSync(options['config-file']);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Favor let over var wherever possible.

Create a new variable name instead of avoiding type checks for contents.

contents = JSON.parse(contents);
if (contents[field] === undefined) {
inputs = [];
Expand Down Expand Up @@ -211,7 +213,6 @@ function runWithOptions(options) {
*/
var fatalFailureOccurred = false;


function prettyPrintWarning(warning) {
if (warning.fatal) {
fatalFailureOccurred = true;
Expand Down Expand Up @@ -260,7 +261,7 @@ function runWithOptions(options) {
}


var lintPromise = Promise.resolve(true);
var lintPromise: Promise<any> = Promise.resolve(true);
var content;

if (options.stdin) {
Expand Down Expand Up @@ -324,9 +325,3 @@ function runWithOptions(options) {
resolve(lintPromise.then(exit));
});
}

module.exports = {
run: run,
runWithOptions: runWithOptions,
argumentDefinitions: argumentDefinitions,
};