Skip to content

Add TSLint to the project #430

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 8 commits into from
Feb 26, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 10 additions & 1 deletion gruntfile.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,14 @@ module.exports = function(grunt)
out: 'src/typings/typescript/typescript.js'
}
},
tslint: {
options: {
configuration: 'tslint.json'
},
files: {
src: [ 'src/**/*.ts' ]
}
},
'string-replace': {
version: {
files: {
Expand Down Expand Up @@ -82,9 +90,10 @@ module.exports = function(grunt)
grunt.loadNpmTasks('grunt-string-replace');
grunt.loadNpmTasks('grunt-contrib-clean');
grunt.loadNpmTasks('grunt-ts');
grunt.loadNpmTasks('grunt-tslint');
grunt.loadNpmTasks('grunt-mocha-istanbul');

grunt.registerTask('default', ['ts:typedoc', 'string-replace:version']);
grunt.registerTask('default', ['tslint', 'ts:typedoc', 'string-replace:version']);
grunt.registerTask('build_and_test', ['default', 'specs', 'mocha_istanbul:coverage']);
grunt.registerTask('specs', ['clean:specsBefore', 'build-specs', 'clean:specsAfter']);

Expand Down
4 changes: 3 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -56,8 +56,10 @@
"grunt-mocha-istanbul": "^5.0.1",
"grunt-string-replace": "^1.2.0",
"grunt-ts": "^5.5.1",
"grunt-tslint": "^4.0.1",
"istanbul": "^0.4.1",
"mocha": "^3.0.2"
"mocha": "^3.0.2",
"tslint": "^4.4.2"
},
"files": [
"bin",
Expand Down
12 changes: 6 additions & 6 deletions src/index.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
export {Application} from "./lib/application";
export {CliApplication} from "./lib/cli";
export {Application} from './lib/application';
export {CliApplication} from './lib/cli';

export {EventDispatcher, Event} from "./lib/utils/events";
export {resetReflectionID} from "./lib/models/reflections/abstract";
export {normalizePath} from "./lib/utils/fs";
export {ProjectReflection} from "./lib/models/reflections/project";
export {EventDispatcher, Event} from './lib/utils/events';
export {resetReflectionID} from './lib/models/reflections/abstract';
export {normalizePath} from './lib/utils/fs';
export {ProjectReflection} from './lib/models/reflections/project';
109 changes: 49 additions & 60 deletions src/lib/application.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,21 +6,19 @@
* in [[TypeDoc.Models]] and the final rendering is defined in [[TypeDoc.Output]].
*/

import * as Path from "path";
import * as FS from "fs";
import * as Util from "util";
import * as typescript from "typescript";
import {Minimatch, IMinimatch} from "minimatch";
import * as Path from 'path';
import * as FS from 'fs';
import * as typescript from 'typescript';
import {Minimatch, IMinimatch} from 'minimatch';

import {Converter} from "./converter/index";
import {Renderer} from "./output/renderer";
import {ProjectReflection} from "./models/index";
import {Logger, ConsoleLogger, CallbackLogger, PluginHost, writeFile} from "./utils/index";

import {AbstractComponent, ChildableComponent, Component, Option} from "./utils/component";
import {Options, OptionsReadMode, IOptionsReadResult} from "./utils/options/index"
import {ParameterType} from "./utils/options/declaration";
import {Converter} from './converter/index';
import {Renderer} from './output/renderer';
import {ProjectReflection} from './models/index';
import {Logger, ConsoleLogger, CallbackLogger, PluginHost, writeFile} from './utils/index';

import {AbstractComponent, ChildableComponent, Component, Option} from './utils/component';
import {Options, OptionsReadMode, OptionsReadResult} from './utils/options/index';
import {ParameterType} from './utils/options/declaration';

/**
* The default TypeDoc main application class.
Expand All @@ -36,63 +34,60 @@ import {ParameterType} from "./utils/options/declaration";
* and emit a series of events while processing the project. Subscribe to these Events
* to control the application flow or alter the output.
*/
@Component({name:"application", internal:true})
export class Application extends ChildableComponent<Application, AbstractComponent<Application>>
{
options:Options;
@Component({name: 'application', internal: true})
export class Application extends ChildableComponent<Application, AbstractComponent<Application>> {
options: Options;

/**
* The converter used to create the declaration reflections.
*/
converter:Converter;
converter: Converter;

/**
* The renderer used to generate the documentation output.
*/
renderer:Renderer;
renderer: Renderer;

/**
* The logger that should be used to output messages.
*/
logger:Logger;
logger: Logger;

plugins:PluginHost;
plugins: PluginHost;

@Option({
name: 'logger',
help: 'Specify the logger that should be used, \'none\' or \'console\'',
defaultValue: 'console',
type: ParameterType.Mixed,
type: ParameterType.Mixed
})
loggerType:string|Function;
loggerType: string|Function;

@Option({
name: 'ignoreCompilerErrors',
help: 'Should TypeDoc generate documentation pages even after the compiler has returned errors?',
type: ParameterType.Boolean
})
ignoreCompilerErrors:boolean;
ignoreCompilerErrors: boolean;

@Option({
name: 'exclude',
help: 'Define a pattern for excluded files when specifying paths.',
type: ParameterType.String
})
exclude:string;
exclude: string;

/**
* The version number of TypeDoc.
*/
static VERSION:string = '{{ VERSION }}';


static VERSION = '{{ VERSION }}';

/**
* Create a new TypeDoc application instance.
*
* @param options An object containing the options that should be used.
*/
constructor(options?:Object) {
constructor(options?: Object) {
super(null);

this.logger = new ConsoleLogger();
Expand All @@ -104,62 +99,56 @@ export class Application extends ChildableComponent<Application, AbstractCompone
this.bootstrap(options);
}


/**
* Initialize TypeDoc with the given options object.
*
* @param options The desired options to set.
*/
protected bootstrap(options?:Object):IOptionsReadResult {
protected bootstrap(options?: Object): OptionsReadResult {
this.options.read(options, OptionsReadMode.Prefetch);

const logger = this.loggerType;
if (typeof logger == 'function') {
this.logger = new CallbackLogger(<any>logger);
} else if (logger == 'none') {
if (typeof logger === 'function') {
this.logger = new CallbackLogger(<any> logger);
} else if (logger === 'none') {
this.logger = new Logger();
}

this.plugins.load();
return this.options.read(options, OptionsReadMode.Fetch);
}


/**
* Return the application / root component instance.
*/
get application():Application {
return this
get application(): Application {
return this;
}


get isCLI():boolean {
get isCLI(): boolean {
return false;
}


/**
* Return the path to the TypeScript compiler.
*/
public getTypeScriptPath():string {
public getTypeScriptPath(): string {
return Path.dirname(require.resolve('typescript'));
}


public getTypeScriptVersion():string {
public getTypeScriptVersion(): string {
const tsPath = this.getTypeScriptPath();
const json = JSON.parse(FS.readFileSync(Path.join(tsPath, '..', 'package.json'), 'utf8'));
return json.version;
}


/**
* Run the converter for the given set of files and return the generated reflections.
*
* @param src A list of source that should be compiled and converted.
* @returns An instance of ProjectReflection on success, NULL otherwise.
*/
public convert(src:string[]):ProjectReflection {
public convert(src: string[]): ProjectReflection {
this.logger.writeln('Using TypeScript %s from %s', this.getTypeScriptVersion(), this.getTypeScriptPath());

const result = this.converter.convert(src);
Expand All @@ -176,26 +165,27 @@ export class Application extends ChildableComponent<Application, AbstractCompone
}
}


/**
* @param src A list of source files whose documentation should be generated.
*/
public generateDocs(src:string[], out:string):boolean;
public generateDocs(src: string[], out: string): boolean;

/**
* @param project The project the documentation should be generated for.
*/
public generateDocs(project:ProjectReflection, out:string):boolean;
public generateDocs(project: ProjectReflection, out: string): boolean;

/**
* Run the documentation generator for the given set of files.
*
* @param out The path the documentation should be written to.
* @returns TRUE if the documentation could be generated successfully, otherwise FALSE.
*/
public generateDocs(input:any, out:string):boolean {
public generateDocs(input: any, out: string): boolean {
const project = input instanceof ProjectReflection ? input : this.convert(input);
if (!project) return false;
if (!project) {
return false;
}

out = Path.resolve(out);
this.renderer.render(project, out);
Expand All @@ -208,26 +198,27 @@ export class Application extends ChildableComponent<Application, AbstractCompone
return true;
}


/**
* @param src A list of source that should be compiled and converted.
*/
public generateJson(src:string[], out:string):boolean;
public generateJson(src: string[], out: string): boolean;

/**
* @param project The project that should be converted.
*/
public generateJson(project:ProjectReflection, out:string):boolean;
public generateJson(project: ProjectReflection, out: string): boolean;

/**
* Run the converter for the given set of files and write the reflections to a json file.
*
* @param out The path and file name of the target file.
* @returns TRUE if the json file could be written successfully, otherwise FALSE.
*/
public generateJson(input:any, out:string):boolean {
public generateJson(input: any, out: string): boolean {
const project = input instanceof ProjectReflection ? input : this.convert(input);
if (!project) return false;
if (!project) {
return false;
}

out = Path.resolve(out);
writeFile(out, JSON.stringify(project.toObject(), null, '\t'), false);
Expand All @@ -236,7 +227,6 @@ export class Application extends ChildableComponent<Application, AbstractCompone
return true;
}


/**
* Expand a list of input files.
*
Expand All @@ -247,13 +237,13 @@ export class Application extends ChildableComponent<Application, AbstractCompone
* @param inputFiles The list of files that should be expanded.
* @returns The list of input files with expanded directories.
*/
public expandInputFiles(inputFiles?:string[]):string[] {
let exclude:IMinimatch, files:string[] = [];
public expandInputFiles(inputFiles?: string[]): string[] {
let exclude: IMinimatch, files: string[] = [];
if (this.exclude) {
exclude = new Minimatch(this.exclude);
}

function add(dirname:string) {
function add(dirname: string) {
FS.readdirSync(dirname).forEach((file) => {
const realpath = Path.join(dirname, file);
if (FS.statSync(realpath).isDirectory()) {
Expand All @@ -280,7 +270,6 @@ export class Application extends ChildableComponent<Application, AbstractCompone
return files;
}


/**
* Print the version number.
*/
Expand Down
Loading