Skip to content

Commit

Permalink
Merge pull request #221 from irvelervel/master
Browse files Browse the repository at this point in the history
Fixes issue #220
  • Loading branch information
pvasek committed Nov 19, 2019
2 parents ea1a993 + b8da535 commit 8cff36b
Show file tree
Hide file tree
Showing 11 changed files with 45 additions and 40 deletions.
3 changes: 2 additions & 1 deletion src/__tests__/data/ColumnWithLog.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,8 @@ export interface IColumnProps {
prop4: 'option1' | 'option2' | 'option3';
}

console.log("test");
// tslint:disable-next-line: no-console
console.log('test');

/**
* Column description
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
export default interface MyExternalType {
name: string;
}
}
5 changes: 4 additions & 1 deletion src/__tests__/data/ColumnWithPropsWithExternalType.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,10 @@ export interface IColumnWithPropsWithExternalTypeProps {
/**
* ColumnWithPropsWithExternalType description
*/
export class ColumnWithPropsWithExternalType extends React.Component<IColumnWithPropsWithExternalTypeProps, {}> {
export class ColumnWithPropsWithExternalType extends React.Component<
IColumnWithPropsWithExternalTypeProps,
{}
> {
public render() {
const { prop1 } = this.props;
return <div>{prop1}</div>;
Expand Down
4 changes: 2 additions & 2 deletions src/__tests__/data/Issue188.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,6 @@ interface Props {
content: string;
}

export const Header = ({content}: Props) => {
export const Header = ({ content }: Props) => {
return <h1>{content}</h1>;
};
};
4 changes: 2 additions & 2 deletions src/__tests__/data/StatelessWithDefaultPropsAsString.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,9 @@ export const StatelessWithDefaultPropsAsString: React.StatelessComponent<

StatelessWithDefaultPropsAsString.defaultProps = {
sampleFalse: false,
sampleNumberWithPrefix: -1,
sampleNull: null,
sampleNumber: 1,
sampleNumberWithPrefix: -1,
sampleTrue: true,
sampleNull: null,
sampleUndefined: undefined
};
2 changes: 1 addition & 1 deletion src/__tests__/data/StatelessWithDestructuredProps.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ export function StatelessWithDefaultProps({
sampleObject = { a: '1', b: 2, c: true, d: false, e: undefined, f: null, g: { a: '1' } },
sampleString = 'hello',
sampleTrue = true,
sampleUndefined = undefined
sampleUndefined
}: StatelessWithDefaultPropsProps) {
return <div>test</div>;
}
2 changes: 1 addition & 1 deletion src/__tests__/data/StatelessWithDestructuredPropsArrow.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -42,5 +42,5 @@ export const StatelessWithDefaultProps: React.StatelessComponent<
sampleObject = { a: '1', b: 2, c: true, d: false, e: undefined, f: null, g: { a: '1' } },
sampleString = 'hello',
sampleTrue = true,
sampleUndefined = undefined
sampleUndefined
}) => <div>test</div>;
13 changes: 4 additions & 9 deletions src/__tests__/data/tsconfig.json
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
{
"compilerOptions": {
/* Basic Options */
"target": "es5", /* Specify ECMAScript target version: 'ES3' (default), 'ES5', 'ES2015', 'ES2016', 'ES2017', or 'ESNEXT'. */
"module": "commonjs", /* Specify module code generation: 'none', 'commonjs', 'amd', 'system', 'umd', 'es2015', or 'ESNext'. */
"target": "es5", /* Specify ECMAScript target version: 'ES3' (default), 'ES5', 'ES2015', 'ES2016', 'ES2017', or 'ESNEXT'. */
"module": "commonjs", /* Specify module code generation: 'none', 'commonjs', 'amd', 'system', 'umd', 'es2015', or 'ESNext'. */
// "lib": [], /* Specify library files to be included in the compilation: */
// "allowJs": true, /* Allow javascript files to be compiled. */
// "checkJs": true, /* Report errors in .js files. */
// "jsx": "preserve", /* Specify JSX code generation: 'preserve', 'react-native', or 'react'. */
"jsx": "preserve", /* Specify JSX code generation: 'preserve', 'react-native', or 'react'. */
// "declaration": true, /* Generates corresponding '.d.ts' file. */
// "sourceMap": true, /* Generates corresponding '.map' file. */
// "outFile": "./", /* Concatenate and emit output to single file. */
Expand All @@ -17,21 +17,18 @@
// "importHelpers": true, /* Import emit helpers from 'tslib'. */
// "downlevelIteration": true, /* Provide full support for iterables in 'for-of', spread, and destructuring when targeting 'ES5' or 'ES3'. */
// "isolatedModules": true, /* Transpile each file as a separate module (similar to 'ts.transpileModule'). */

/* Strict Type-Checking Options */
"strict": true /* Enable all strict type-checking options. */
"strict": true /* Enable all strict type-checking options. */
// "noImplicitAny": true, /* Raise error on expressions and declarations with an implied 'any' type. */
// "strictNullChecks": true, /* Enable strict null checks. */
// "strictFunctionTypes": true, /* Enable strict checking of function types. */
// "noImplicitThis": true, /* Raise error on 'this' expressions with an implied 'any' type. */
// "alwaysStrict": true, /* Parse in strict mode and emit "use strict" for each source file. */

/* Additional Checks */
// "noUnusedLocals": true, /* Report errors on unused locals. */
// "noUnusedParameters": true, /* Report errors on unused parameters. */
// "noImplicitReturns": true, /* Report error when not all code paths in function return a value. */
// "noFallthroughCasesInSwitch": true, /* Report errors for fallthrough cases in switch statement. */

/* Module Resolution Options */
// "moduleResolution": "node", /* Specify module resolution strategy: 'node' (Node.js) or 'classic' (TypeScript pre-1.6). */
// "baseUrl": "./", /* Base directory to resolve non-absolute module names. */
Expand All @@ -41,13 +38,11 @@
// "types": [], /* Type declaration files to be included in compilation. */
// "allowSyntheticDefaultImports": true, /* Allow default imports from modules with no default export. This does not affect code emit, just typechecking. */
// "preserveSymlinks": true, /* Do not resolve the real path of symlinks. */

/* Source Map Options */
// "sourceRoot": "./", /* Specify the location where debugger should locate TypeScript files instead of source locations. */
// "mapRoot": "./", /* Specify the location where debugger should locate map files instead of generated locations. */
// "inlineSourceMap": true, /* Emit a single file with source maps instead of having a separate file. */
// "inlineSources": true, /* Emit the source alongside the sourcemaps within a single file; requires '--inlineSourceMap' or '--sourceMap' to be set. */

/* Experimental Options */
// "experimentalDecorators": true, /* Enables experimental support for ES7 decorators. */
// "emitDecoratorMetadata": true, /* Enables experimental support for emitting type metadata for decorators. */
Expand Down
30 changes: 15 additions & 15 deletions src/__tests__/parser.ts
Original file line number Diff line number Diff line change
Expand Up @@ -815,30 +815,30 @@ describe('parser', () => {
required: false,
type: 'boolean'
},
sampleNumberWithPrefix: {
type: 'number',
sampleNull: {
defaultValue: 'null',
required: false,
defaultValue: '-1'
type: 'null'
},
sampleNumber: {
type: 'number',
defaultValue: '1',
required: false,
defaultValue: '1'
type: 'number'
},
sampleTrue: {
type: 'boolean',
sampleNumberWithPrefix: {
defaultValue: '-1',
required: false,
defaultValue: 'true'
type: 'number'
},
sampleNull: {
type: 'null',
sampleTrue: {
defaultValue: 'true',
required: false,
defaultValue: 'null'
type: 'boolean'
},
sampleUndefined: {
type: 'undefined',
defaultValue: 'undefined',
required: false,
defaultValue: 'undefined'
type: 'undefined'
}
}
},
Expand Down Expand Up @@ -947,8 +947,8 @@ describe('parser', () => {
assert.equal(myCoolMethod.description, 'My super cool method');
assert.equal(
myCoolMethod.docblock,
'My super cool method\n@param myParam Documentation for parameter 1\n@public\n@returns The answer to the universe'
); // tslint:disable-line max-line-length
'My super cool method\n@param myParam Documentation for parameter 1\n@public\n@returns The answer to the universe' // tslint:disable-line max-line-length
);
assert.deepEqual(myCoolMethod.modifiers, []);
assert.equal(myCoolMethod.name, 'myCoolMethod');
assert.deepEqual(myCoolMethod.params, [
Expand Down
2 changes: 1 addition & 1 deletion src/__tests__/testUtils.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { assert } from 'chai';
import * as path from 'path';
import { isEqual } from 'lodash';
import * as path from 'path';
import {
ComponentDoc,
defaultParserOpts,
Expand Down
18 changes: 12 additions & 6 deletions src/parser.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ export interface Method {
name: string;
docblock: string;
modifiers: string[];
params: Array<MethodParameter>;
params: MethodParameter[];
returns?: {
description?: string | null;
type?: string;
Expand Down Expand Up @@ -136,7 +136,10 @@ export function withCustomConfig(
);

if (error !== undefined) {
const errorText = `Cannot load custom tsconfig.json from provided path: ${tsconfigPath}, with error code: ${error.code}, message: ${error.messageText}`;
// tslint:disable-next-line: max-line-length
const errorText = `Cannot load custom tsconfig.json from provided path: ${tsconfigPath}, with error code: ${
error.code
}, message: ${error.messageText}`;
throw new Error(errorText);
}

Expand Down Expand Up @@ -413,7 +416,7 @@ export class Parser {
return modifiers;
}

public getParameterInfo(callSignature: ts.Signature): Array<MethodParameter> {
public getParameterInfo(callSignature: ts.Signature): MethodParameter[] {
return callSignature.parameters.map(param => {
const paramType = this.checker.getTypeOfSymbolAtLocation(
param,
Expand Down Expand Up @@ -603,7 +606,9 @@ export class Parser {
}

if (ts.isVariableStatement(statement)) {
const initializer = statement.declarationList && statement.declarationList.declarations[0].initializer;
const initializer =
statement.declarationList &&
statement.declarationList.declarations[0].initializer;

if (
initializer &&
Expand Down Expand Up @@ -855,9 +860,10 @@ function getTextValueOfClassMember(
classDeclaration: ts.ClassDeclaration,
memberName: string
): string {
const classDeclarationMembers = classDeclaration.members || [];
const [textValue] =
classDeclaration.members &&
classDeclaration.members
classDeclarationMembers &&
classDeclarationMembers
.filter(member => ts.isPropertyDeclaration(member))
.filter(member => {
const name = ts.getNameOfDeclaration(member) as ts.Identifier;
Expand Down

0 comments on commit 8cff36b

Please sign in to comment.