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 all commits
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
3 changes: 3 additions & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,7 @@ node_js:
sudo: false
before_script:
- npm install -g bower
- npm install -g typescript
- bower install
- typings install
- tsc
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[];
}
}
5 changes: 5 additions & 0 deletions custom_typings/plylog.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
declare module "plylog" {
function getLogger(logger: string);
function setQuiet();
function setVerbose();
}
49 changes: 0 additions & 49 deletions lib/case-map.js

This file was deleted.

14 changes: 8 additions & 6 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 @@ -19,17 +19,19 @@
"homepage": "https://github.com/PolymerLabs/polylint",
"dependencies": {
"colors": "^1.1.0",
"command-line-args": "^2.1.1",
"command-line-args": "^2.1.6",
"dom5": "^1.0.2",
"es6-set": "^0.1.4",
"hydrolysis": "^1.21.4",
"optimist": "^0.6.1",
"path-is-absolute": "^1.0.0"
"path-is-absolute": "^1.0.0",
"plylog": "^0.4.0"
},
"devDependencies": {
"bower": "^1.6.5",
"chai": "^2.3.0",
"jshint": "^2.7.0",
"mocha": "^2.2.4"
"mocha": "^2.2.4",
"typings": "^0.8.1"
}
}
105 changes: 105 additions & 0 deletions src/args.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,105 @@
/**
* @license
* Copyright (c) 2015 The Polymer Project Authors. All rights reserved.
* This code may only be used under the BSD style license found at http://polymer.github.io/LICENSE.txt
* The complete set of authors may be found at http://polymer.github.io/AUTHORS.txt
* The complete set of contributors may be found at http://polymer.github.io/CONTRIBUTORS.txt
* Code distributed by Google as part of the polymer project is also
* subject to an additional IP rights grant found at http://polymer.github.io/PATENTS.txt
*/

module.exports = {
argumentDefinitions: [
{
name: "help",
type: Boolean,
alias: "h",
description: "Print usage."
},
{
name: "bowerdir",
type: String,
alias: "b",
description: "Bower components directory. Defaults to 'bower_components'",
defaultValue: "bower_components"
},
{
name: "verbose",
type: Boolean,
alias: "v",
description: "Writes verbose logging."
},
{
name: 'quiet',
description: 'silence output',
type: Boolean,
alias: 'q',
},
{
name: "debug",
type: Boolean,
alias: "g",
description: "Writes debugging trace."
},
{
name: "policy",
type: String,
alias: "p",
description: "Your jsconf.json policy file.",
defaultValue: null
},
{
name: "root",
type: String,
defaultValue: '',
alias: "r",
description: (
"Root directory against which URLs in inputs are resolved." +
" If not specified, then the current working directory is used."
)
},
{
name: "input",
type: String,
alias: "i",
defaultOption: true,
multiple: true,
description: (
"Polymer source files."
)
},
{
name: "config-file",
type: String,
defaultValue: "bower.json",
description: (
"If inputs are specified, look for `config-field` in this JSON file."
)
},
{
name: "config-field",
type: String,
defaultValue: "main",
description: (
"If config-file is used for inputs, this field determines which " +
"file(s) are linted."
)
},
{
name: "stdin",
type: Boolean,
defaultValue: false,
description: (
"If true, the file from `input` will be replaced by the contents of stdin." +
" If true, only one value will be accepted for input."
)
},
{
name: "no-recursion",
type: Boolean,
description: (
"Only report errors on specified input files, not from their dependencies."
)
}
],
};