Skip to content

Commit

Permalink
refactor: types
Browse files Browse the repository at this point in the history
  • Loading branch information
0xGorilla committed Jan 13, 2024
1 parent 55e85c1 commit ffe5608
Show file tree
Hide file tree
Showing 13 changed files with 61 additions and 67 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ npx @defi-wonderland/natspec-smells --include solidity --exclude solidity/(test|

```javascript
/**
* For full explanation of each supported config, make sure to check the Config type below
* List of supported options: https://github.com/defi-wonderland/natspec-smells?tab=readme-ov-file#options
*/

/** @type {import('@defi-wonderland/natspec-smells').Config} */
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
"license": "MIT",
"author": "Wonderland",
"main": "lib/main.js",
"types": "lib/main.js",
"types": "lib/types.d.ts",
"bin": "./lib/main.js",
"scripts": {
"build": "tsc",
Expand Down
5 changes: 1 addition & 4 deletions src/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,9 @@ import { hideBin } from 'yargs/helpers';
import { globSync } from 'fast-glob';
import { getProjectCompiledSources } from './utils';
import { Processor } from './processor';
import { Config } from './types/config';
import { Config } from './types';
import { Validator } from './validator';

// export config for type reference
export { Config } from './types/config';

(async () => {
const config: Config = getArguments();

Expand Down
2 changes: 1 addition & 1 deletion src/processor.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import fs from 'fs/promises';
import { Validator } from './validator';
import { SourceUnit, FunctionDefinition, ContractDefinition } from 'solc-typed-ast';
import { NodeToProcess } from './types/solc-typed-ast.d';
import { NodeToProcess } from './types';
import { getLineNumberFromSrc, parseNodeNatspec } from './utils';

interface IWarning {
Expand Down
51 changes: 51 additions & 0 deletions src/types.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
import {
EnumDefinition,
ErrorDefinition,
EventDefinition,
FunctionDefinition,
ModifierDefinition,
StructDefinition,
VariableDeclaration,
} from 'solc-typed-ast';

export interface Config {
include: string; // Required: Glob pattern of files to process.
exclude: string[]; // Optional: Glob patterns of files to exclude.
root: string; // Optional: Project root directory.
enforceInheritdoc: boolean; // Optional: True if all external and public functions should have @inheritdoc.
constructorNatspec: boolean; // Optional: True if the constructor should have natspec.
}

export interface NatspecDefinition {
name?: string;
content: string;
}

export interface Natspec {
inheritdoc?: NatspecDefinition;
tags: NatspecDefinition[];
params: NatspecDefinition[];
returns: NatspecDefinition[];
}

export interface ASTNodeRawDocumentation {
id: number;
nodeType: string;
src: string;
text: string;
}

export interface ASTNodeRaw {
name: string;
kind: string;
documentation?: ASTNodeRawDocumentation;
}

export type NodeToProcess =
| FunctionDefinition
| EnumDefinition
| ErrorDefinition
| EventDefinition
| ModifierDefinition
| VariableDeclaration
| StructDefinition;
7 changes: 0 additions & 7 deletions src/types/config.d.ts

This file was deleted.

11 changes: 0 additions & 11 deletions src/types/natspec.d.ts

This file was deleted.

31 changes: 0 additions & 31 deletions src/types/solc-typed-ast.d.ts

This file was deleted.

3 changes: 1 addition & 2 deletions src/utils.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
import fs from 'fs/promises';
import path from 'path';
import { ASTKind, ASTReader, SourceUnit, compileSol } from 'solc-typed-ast';
import { Natspec, NatspecDefinition } from './types/natspec.d';
import { NodeToProcess } from './types/solc-typed-ast.d';
import { Natspec, NatspecDefinition, NodeToProcess } from './types';

export async function getSolidityFiles(dir: string): Promise<string[]> {
let files = await fs.readdir(dir, { withFileTypes: true });
Expand Down
4 changes: 1 addition & 3 deletions src/validator.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
import { Config } from './types/config';
import { Natspec } from './types/natspec';
import { NodeToProcess } from './types/solc-typed-ast';
import { Config, Natspec, NodeToProcess } from './types';
import {
EnumDefinition,
ErrorDefinition,
Expand Down
3 changes: 1 addition & 2 deletions test/mocks.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import { Natspec } from '../src/types/natspec.d';
import { SourceUnit, ContractDefinition, FunctionDefinition } from 'solc-typed-ast';
import { NodeToProcess } from '../src/types/solc-typed-ast.d';
import { Natspec, NodeToProcess } from '../src/types';

export function mockNatspec(mockNatspec: Partial<Natspec>): Natspec {
const natspec: Natspec = {
Expand Down
2 changes: 1 addition & 1 deletion test/processor.test.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { Config } from '../src/types/config';
import { ContractDefinition, FunctionDefinition, UserDefinedType, UsingForDirective } from 'solc-typed-ast';
import { Config } from '../src/types';
import { getFileCompiledSource } from './utils';
import { Processor } from '../src/processor';
import { Validator } from '../src/validator';
Expand Down
5 changes: 2 additions & 3 deletions test/validator.test.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
import { ContractDefinition } from 'solc-typed-ast';
import { Validator } from '../src/validator';
import { getFileCompiledSource } from './utils';
import { NodeToProcess } from '../src/types/solc-typed-ast.d';
import { ContractDefinition } from 'solc-typed-ast';
import { Config } from '../src/types/config';
import { Config, NodeToProcess } from '../src/types';

describe('Validator', () => {
let contract: ContractDefinition;
Expand Down

0 comments on commit ffe5608

Please sign in to comment.