remix-astwalker linting done

pull/8/head
aniket-engg 4 years ago
parent dafbe6f1fe
commit 83cc0cb71a
  1. 7
      libs/remix-astwalker/.eslintrc
  2. 32
      libs/remix-astwalker/src/astWalker.ts
  3. 11
      libs/remix-astwalker/src/sourceMappings.ts
  4. 4
      libs/remix-astwalker/src/types.ts
  5. 34
      libs/remix-astwalker/tsconfig.json
  6. 13
      libs/remix-astwalker/tsconfig.lib.json
  7. 12
      workspace.json

@ -0,0 +1,7 @@
{
"extends": "../../.eslintrc",
"rules": {
"@typescript-eslint/no-explicit-any": "off"
},
"ignorePatterns": ["!**/*"]
}

@ -9,7 +9,7 @@ const isObject = function(obj: any): boolean {
return obj != null && obj.constructor.name === "Object"
}
export function isAstNode(node: Object): boolean {
export function isAstNode(node: Record<string, unknown>): boolean {
return (
isObject(node) &&
'id' in node &&
@ -35,7 +35,7 @@ export function isAstNode(node: Object): boolean {
export class AstWalker extends EventEmitter {
manageCallback(
node: AstNodeLegacy | AstNode,
callback: Object | Function
callback: Record<string, unknown> | Function // eslint-disable-line @typescript-eslint/ban-types
): any {
// FIXME: we shouldn't be doing this callback determination type on each AST node,
// since the callback function is set once per walk.
@ -58,7 +58,8 @@ export class AstWalker extends EventEmitter {
}
}
}
walk(ast: AstNodeLegacy | AstNode, callback?: Function | Object) {
// eslint-disable-next-line @typescript-eslint/ban-types, @typescript-eslint/explicit-module-boundary-types
walk(ast: AstNodeLegacy | AstNode, callback?: Function | Record<string, unknown>) {
if (callback) {
if (callback instanceof Function) {
callback = Object({ "*": callback });
@ -74,8 +75,8 @@ export class AstWalker extends EventEmitter {
(<AstNodeLegacy>ast).children &&
(<AstNodeLegacy>ast).children.length > 0
) {
for (let k in (<AstNodeLegacy>ast).children) {
let child = (<AstNodeLegacy>ast).children[k];
for (const k in (<AstNodeLegacy>ast).children) {
const child = (<AstNodeLegacy>ast).children[k];
this.walk(child, callback);
}
}
@ -85,8 +86,8 @@ export class AstWalker extends EventEmitter {
(<AstNode>ast).nodes &&
(<AstNode>ast).nodes.length > 0
) {
for (let k in (<AstNode>ast).nodes) {
let child = (<AstNode>ast).nodes[k];
for (const k in (<AstNode>ast).nodes) {
const child = (<AstNode>ast).nodes[k];
this.walk(child, callback);
}
}
@ -97,8 +98,8 @@ export class AstWalker extends EventEmitter {
(<AstNodeLegacy>ast).children &&
(<AstNodeLegacy>ast).children.length > 0
) {
for (let k in (<AstNodeLegacy>ast).children) {
let child = (<AstNodeLegacy>ast).children[k];
for (const k in (<AstNodeLegacy>ast).children) {
const child = (<AstNodeLegacy>ast).children[k];
this.emit("node", child);
this.walk(child);
}
@ -106,8 +107,8 @@ export class AstWalker extends EventEmitter {
}
if (<AstNode>ast) {
if ((<AstNode>ast).nodes && (<AstNode>ast).nodes.length > 0) {
for (let k in (<AstNode>ast).nodes) {
let child = (<AstNode>ast).nodes[k];
for (const k in (<AstNode>ast).nodes) {
const child = (<AstNode>ast).nodes[k];
this.emit("node", child);
this.walk(child);
}
@ -115,18 +116,18 @@ export class AstWalker extends EventEmitter {
}
}
}
// eslint-disable-next-line @typescript-eslint/ban-types, @typescript-eslint/explicit-module-boundary-types
walkFullInternal(ast: AstNode, callback: Function) {
if (isAstNode(ast)) {
// console.log(`XXX id ${ast.id}, nodeType: ${ast.nodeType}, src: ${ast.src}`);
callback(ast);
for (let k of Object.keys(ast)) {
for (const k of Object.keys(ast)) {
// Possible optimization:
// if (k in ['id', 'src', 'nodeType']) continue;
const astItem = ast[k];
if (Array.isArray(astItem)) {
for (let child of astItem) {
for (const child of astItem) {
if (child) {
this.walkFullInternal(child, callback);
}
@ -139,12 +140,13 @@ export class AstWalker extends EventEmitter {
}
// Normalizes parameter callback and calls walkFullInternal
// eslint-disable-next-line @typescript-eslint/explicit-module-boundary-types
walkFull(ast: AstNode, callback: any) {
if (!isAstNode(ast)) throw new TypeError("first argument should be an ast");
return this.walkFullInternal(ast, callback);
}
// eslint-disable-next-line @typescript-eslint/ban-types, @typescript-eslint/explicit-module-boundary-types
walkAstList(sourcesList: Node, cb?: Function) {
if (cb) {
if (sourcesList.ast) {

@ -3,6 +3,7 @@ import { AstNode, LineColPosition, LineColRange, Location } from "./types";
import { util } from "remix-lib";
export declare interface SourceMappings {
// eslint-disable-next-line @typescript-eslint/no-misused-new
new(): SourceMappings;
}
@ -67,8 +68,8 @@ export class SourceMappings {
// Create a list of line offsets which will be used to map between
// character offset and line/column positions.
let lineBreaks: Array<number> = [];
for (var pos = source.indexOf('\n'); pos >= 0; pos = source.indexOf('\n', pos + 1)) {
const lineBreaks: Array<number> = [];
for (let pos = source.indexOf('\n'); pos >= 0; pos = source.indexOf('\n', pos + 1)) {
lineBreaks.push(pos)
}
this.lineBreaks = lineBreaks;
@ -82,10 +83,10 @@ export class SourceMappings {
*/
nodesAtPosition(astNodeType: string | null, position: Location, ast: AstNode): Array<AstNode> {
const astWalker = new AstWalker()
let found: Array<AstNode> = [];
const found: Array<AstNode> = [];
const callback = function(node: AstNode): boolean {
let nodeLocation = sourceLocationFromAstNode(node);
const nodeLocation = sourceLocationFromAstNode(node);
if (nodeLocation &&
nodeLocation.start == position.start &&
nodeLocation.length == position.length) {
@ -111,7 +112,7 @@ export class SourceMappings {
/* FIXME: Looking at AST walker code,
I don't understand a need to return a boolean. */
const callback = function(node: AstNode) {
let nodeLocation = sourceLocationFromAstNode(node);
const nodeLocation = sourceLocationFromAstNode(node);
if (nodeLocation &&
nodeLocation.start == sourceLocation.start &&
nodeLocation.length == sourceLocation.length) {

@ -37,7 +37,7 @@ export interface AstNode {
src: string;
absolutePath?: string;
exportedSymbols?: Object;
exportedSymbols?: Record<string, unknown>;
nodes?: Array<AstNode>;
literals?: Array<string>;
file?: string;
@ -63,7 +63,7 @@ export interface AstNodeAtt {
constant?: boolean;
name?: string;
public?: boolean;
exportedSymbols?: Object;
exportedSymbols?: Record<string, unknown>;
argumentTypes?: null;
absolutePath?: string;
[x: string]: any;

@ -1,31 +1,7 @@
{
"include": ["src"],
"exclude": ["node_modules", "src/@types" ],
"extends": "../../tsconfig.json",
"compilerOptions": {
/* Basic Options */
"target": "es5", /* Specify ECMAScript target version: 'ES3' (default), 'ES5', 'ES2015', 'ES2016', 'ES2017','ES2018' or 'ESNEXT'. */
"module": "commonjs", /* Specify module code generation: 'none', 'commonjs', 'amd', 'system', 'umd', 'es2015', or 'ESNext'. */
"lib": ["dom", "es2018"], /* Specify library files to be included in the compilation. */
"declaration": true, /* Generates corresponding '.d.ts' file. */
"sourceMap": true, /* Generates corresponding '.map' file. */
"outDir": "./dist", /* Redirect output structure to the directory. */
/* Strict Type-Checking Options */
"strict": true, /* Enable all strict type-checking options. */
"noImplicitAny": false, /* Raise error on expressions and declarations with an implied 'any' type. */
/* Module Resolution Options */
"baseUrl": "./src", /* Base directory to resolve non-absolute module names. */
"paths": { "remix-tests": ["./"] }, /* A series of entries which re-map imports to lookup locations relative to the 'baseUrl'. */
"typeRoots": ["./@types", "node_modules/@types"], /* List of folders to include type definitions from. */
"esModuleInterop": true, /* Enables emit interoperability between CommonJS and ES Modules via creation of namespace objects for all imports. Implies 'allowSyntheticDefaultImports'. */
"types": [
"node"
],
/* Experimental Options */
"experimentalDecorators": true, /* Enables experimental support for ES7 decorators. */
"allowSyntheticDefaultImports": true,
// Disables strictNullChecks
"strictNullChecks": false
}
}
"types": ["node"],
},
"include": ["**/*.ts"]
}

@ -0,0 +1,13 @@
{
"extends": "./tsconfig.json",
"compilerOptions": {
"module": "commonjs",
"outDir": "../../dist/out-tsc",
"declaration": true,
"rootDir": "./src",
"types": ["node"]
},
"exclude": ["**/*.spec.ts"],
"include": ["**/*.ts"]
}

@ -117,14 +117,14 @@
"schematics": {},
"architect": {
"lint": {
"builder": "@nrwl/workspace:run-commands",
"builder": "@nrwl/linter:lint",
"options": {
"commands": [
{
"command": "./../../node_modules/.bin/npm-run-all lint"
}
"linter": "eslint",
"config": "libs/remix-astwalker/.eslintrc",
"tsConfig": [
"libs/remix-astwalker/tsconfig.lib.json"
],
"cwd": "libs/remix-astwalker"
"exclude": ["**/node_modules/**", "libs/remix-astwalker/tests/**/*"]
}
},
"test": {

Loading…
Cancel
Save