Skip to content

Commit

Permalink
Merge pull request #117 from masterchief01/linter-formatter
Browse files Browse the repository at this point in the history
Linter formatter
  • Loading branch information
rajitha1998 authored Jun 19, 2022
2 parents 944de49 + bc6166a commit c859719
Show file tree
Hide file tree
Showing 34 changed files with 666 additions and 45 deletions.
2 changes: 2 additions & 0 deletions .eslintignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
node_modules
dist
18 changes: 18 additions & 0 deletions .eslintrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
{
"root": true,
"parser": "@typescript-eslint/parser",
"plugins": ["@typescript-eslint", "simple-import-sort"],
"extends": [
"eslint:recommended",
"plugin:@typescript-eslint/eslint-recommended",
"plugin:@typescript-eslint/recommended"
],
"rules": {
"prefer-const": "warn",
"no-unused-vars": "warn",
"no-async-promise-executor": "off",
"@typescript-eslint/no-inferrable-types": "off",
"simple-import-sort/imports": "error",
"simple-import-sort/exports": "error"
}
}
3 changes: 3 additions & 0 deletions .prettierignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
node_modules
dist
coverage
7 changes: 7 additions & 0 deletions .prettierrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{
"tabWidth": 4,
"singleQuote": true,
"printWidth": 80,
"useTabs": true,
"trailingComma": "es5"
}
12 changes: 12 additions & 0 deletions generator/.eslintrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
{
"extends": "../.eslintrc",
"ignorePatterns": [
"*.js",
"node_modules/",
"dummyClasses/",
"generatedClasses/"
],
"rules": {
"@typescript-eslint/no-empty-function": "warn"
}
}
3 changes: 2 additions & 1 deletion generator/generators/aws/generator.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
import * as fs from "fs";
import { createSourceFile, ScriptTarget, SyntaxKind } from "typescript";

import { getAST } from "../../parsers/aws/parser";
import { transform } from "../../transformers/aws/transformer";
import { filters, groupers, printFile, getDir } from "../lib/helper";
import { filters, getDir,groupers, printFile } from "../lib/helper";

interface FunctionData {
functionName: string;
Expand Down
5 changes: 3 additions & 2 deletions generator/generators/azure/generator.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
import * as fs from "fs";
import { SyntaxKind, createSourceFile, ScriptTarget } from "typescript";
import { createSourceFile, ScriptTarget,SyntaxKind } from "typescript";

import { getAST } from "../../parsers/azure/parser";
import { groupers, filters, printFile, getDir } from "../lib/helper";
import { transform } from "../../transformers/azure/transformer";
import { filters, getDir,groupers, printFile } from "../lib/helper";

interface FunctionData {
pkgName: string;
Expand Down
3 changes: 2 additions & 1 deletion generator/generators/do/generator.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
import * as fs from "fs";
import { createSourceFile, ScriptTarget, SyntaxKind } from "typescript";

import { getAST } from "../../parsers/do/parser";
import { transform } from "../../transformers/do/transformer";
import { printFile, getDir } from "../lib/helper";
import { getDir,printFile } from "../lib/helper";

interface FunctionData {
functionName: string;
Expand Down
7 changes: 4 additions & 3 deletions generator/generators/googleCloud/generator.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
import * as fs from "fs";
import * as path from "path";
import { SyntaxKind, createSourceFile, ScriptTarget } from "typescript";
import { createSourceFile, ScriptTarget,SyntaxKind } from "typescript";

import { getAST } from "../../parsers/googleCloud/parser";
import { filters, groupers, printFile, getDir } from "../lib/helper";
import { clientBasedTransform } from "../../transformers/googleCloud/clientBasedTransformer";
import { classBasedTransform } from "../../transformers/googleCloud/classBasedTransformer";
import { clientBasedTransform } from "../../transformers/googleCloud/clientBasedTransformer";
import { filters, getDir,groupers, printFile } from "../lib/helper";

interface ClassData {
name: string;
Expand Down
11 changes: 5 additions & 6 deletions generator/generators/lib/helper.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,11 @@
import * as fs from "fs";

import { groupAWSMethods } from "../lib/aws/awsHelper";
import { groupGCPMethods } from "../lib/googleCloud/gcpHelper";
import { groupAzureMethods } from "../lib/azure/azureHelper";

import { filterAWSMethods } from "../lib/aws/awsHelper";
import { filterGCPMethods } from "../lib/googleCloud/gcpHelper";
import { groupAzureMethods } from "../lib/azure/azureHelper";
import { filterAzureMethods } from "../lib/azure/azureHelper";
import { groupGCPMethods } from "../lib/googleCloud/gcpHelper";
import { filterGCPMethods } from "../lib/googleCloud/gcpHelper";

const dirMap = {
appServices: ["PaaS"],
Expand Down Expand Up @@ -38,12 +37,12 @@ const filters = {
};

const getDir = (service: string): string => {
for (var dir in dirMap) {
for (let dir in dirMap) {
if (dirMap[dir].includes(service)) {
return dir;
}
}
throw new Error("Not a valid service: " + service);
};

export { groupers, filters, getDir };
export { filters, getDir,groupers };
5 changes: 3 additions & 2 deletions generator/main.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
import * as yaml from "js-yaml";
import * as fs from "fs";
import * as yaml from "js-yaml";

import { generateAWSClass } from "./generators/aws/generator";
import { generateAzureClass } from "./generators/azure/generator";
import { generateGCPClass } from "./generators/googleCloud/generator";
import { generateDOClass } from "./generators/do/generator";
import { generateGCPClass } from "./generators/googleCloud/generator";

try {
const services = yaml.safeLoad(fs.readFileSync("node-cloud.yml", "utf8"));
Expand Down
4 changes: 3 additions & 1 deletion generator/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,9 @@
],
"scripts": {
"test": "cross-env TS_NODE_FILES=true mocha --exit --require ts-node/register --colors test/**/*.ts",
"tool": "tsc main && node main"
"tool": "tsc main && node main",
"lint": "eslint .",
"lint-fix": "eslint --fix ."
},
"dependencies": {
"@azure/arm-appservice": "^6.0.0",
Expand Down
5 changes: 3 additions & 2 deletions generator/test/generators/aws/generator.test.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
import { expect } from "chai";
import { extractSDKData } from "../../../generators/aws/generator";
import { readSourceFile, readJsonData } from "../lib/helper";
import { SyntaxKind } from "typescript";

import { extractSDKData } from "../../../generators/aws/generator";
import { readJsonData,readSourceFile } from "../lib/helper";

describe("AWS generator extractSDKData", () => {
context("with valid methods and valid AST", () => {
it("should return extracted class data", async () => {
Expand Down
5 changes: 3 additions & 2 deletions generator/test/generators/azure/generator.test.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
import { expect } from "chai";
import { extractSDKData } from "../../../generators/azure/generator";
import { SyntaxKind } from "typescript";
import { readSourceFile, readJsonData } from "../lib/helper";

import { extractSDKData } from "../../../generators/azure/generator";
import { readJsonData,readSourceFile } from "../lib/helper";

describe("Azure generator extractSDKData", () => {
context("with valid methods and valid AST", () => {
Expand Down
5 changes: 3 additions & 2 deletions generator/test/generators/do/generator.test.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
import { expect } from "chai";
import { extractSDKData } from "../../../generators/do/generator";
import { readSourceFile, readJsonData } from "../lib/helper";
import { SyntaxKind } from "typescript";

import { extractSDKData } from "../../../generators/do/generator";
import { readJsonData,readSourceFile } from "../lib/helper";

describe("Digital Ocean generator extractSDKData", () => {
context("with valid methods and valid AST", () => {
it("should return extracted class data", async () => {
Expand Down
3 changes: 2 additions & 1 deletion generator/test/generators/googleCloud/generator.test.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
import { expect } from "chai";
import { SyntaxKind } from "typescript";

import {
extractClassBasedSDKData,
extractClientBasedSDKdata
} from "../../../generators/googleCloud/generator";
import { readJsonData, readSourceFile } from "../lib/helper";
import { SyntaxKind } from "typescript";

describe("GCP generator extractClassBasedSDKData", () => {
context("with valid methods and valid AST", () => {
Expand Down
2 changes: 1 addition & 1 deletion generator/test/generators/lib/helper.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import * as fs from "fs";
import { ScriptTarget, createSourceFile } from "typescript";
import { createSourceFile,ScriptTarget } from "typescript";

export function readSourceFile(datasetName, provider) {
return new Promise((resolve, reject) => {
Expand Down
3 changes: 2 additions & 1 deletion generator/test/parsers/aws/parser.test.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
import { expect } from "chai";
import { getAST } from "../../../parsers/aws/parser";
import { SyntaxKind } from "typescript";

import { getAST } from "../../../parsers/aws/parser";

describe("AWS parser getAST", () => {
context("with existing file", () => {
it("should return Abstract syntax tree of the class", async () => {
Expand Down
3 changes: 2 additions & 1 deletion generator/test/parsers/azure/parser.test.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
import { expect } from "chai";
import { getAST } from "../../../parsers/azure/parser";
import { SyntaxKind } from "typescript";

import { getAST } from "../../../parsers/azure/parser";

describe("Azure parser getAST", () => {
context("with existing file", () => {
it("should return Abstract syntax tree of the class", async () => {
Expand Down
3 changes: 2 additions & 1 deletion generator/test/parsers/do/parser.test.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
import { expect } from "chai";
import { getAST } from "../../../parsers/do/parser";
import { SyntaxKind } from "typescript";

import { getAST } from "../../../parsers/do/parser";

describe("Digital Ocean parser getAST", () => {
context("With existing file", () => {
it("Should return Abstract syntax tree of the class", async () => {
Expand Down
3 changes: 2 additions & 1 deletion generator/test/parsers/googleCloud/parser.test.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
import { expect } from "chai";
import { getAST } from "../../../parsers/googleCloud/parser";
import { SyntaxKind } from "typescript";

import { getAST } from "../../../parsers/googleCloud/parser";

describe("Google cloud parser getAST", () => {
context("with existing file, multi:false", () => {
it("should return Abstract syntax tree of the class", async () => {
Expand Down
3 changes: 2 additions & 1 deletion generator/test/transformers/aws/transformer.test.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { expect } from "chai";
import { createSourceFile, isSourceFile,ScriptTarget } from "typescript";

import { transform } from "../../../transformers/aws/transformer";
import { createSourceFile, ScriptTarget, isSourceFile } from "typescript";
import { readJsonData, readSourceFile } from "../lib/helper";

interface TestData {
Expand Down
3 changes: 2 additions & 1 deletion generator/test/transformers/azure/transformer.test.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { expect } from "chai";
import { createSourceFile, isSourceFile,ScriptTarget } from "typescript";

import { transform } from "../../../transformers/azure/transformer";
import { createSourceFile, ScriptTarget, isSourceFile } from "typescript";
import { readJsonData, readSourceFile } from "../lib/helper";

interface TestData {
Expand Down
3 changes: 2 additions & 1 deletion generator/test/transformers/do/transformer.test.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { expect } from "chai";
import { createSourceFile, isSourceFile,ScriptTarget } from "typescript";

import { transform } from "../../../transformers/do/transformer";
import { createSourceFile, ScriptTarget, isSourceFile } from "typescript";
import { readJsonData, readSourceFile } from "../lib/helper";

interface TestData {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { expect } from "chai";
import { createSourceFile, isSourceFile,ScriptTarget } from "typescript";

import { classBasedTransform } from "../../../transformers/googleCloud/classBasedTransformer";
import { createSourceFile, ScriptTarget, isSourceFile } from "typescript";
import { readJsonData, readSourceFile } from "../lib/helper";

interface TestData {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { expect } from "chai";
import { createSourceFile, isSourceFile,ScriptTarget } from "typescript";

import { clientBasedTransform } from "../../../transformers/googleCloud/clientBasedTransformer";
import { createSourceFile, ScriptTarget, isSourceFile } from "typescript";
import { readJsonData, readSourceFile } from "../lib/helper";

interface TestData {
Expand Down
2 changes: 1 addition & 1 deletion generator/test/transformers/lib/helper.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import * as fs from "fs";
import { ScriptTarget, createSourceFile } from "typescript";
import { createSourceFile,ScriptTarget } from "typescript";

export function readSourceFile(datasetName, provider) {
return new Promise((resolve, reject) => {
Expand Down
2 changes: 1 addition & 1 deletion generator/transformers/aws/transformer.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import * as ts from "typescript";
import { cloneDeep } from "lodash";
import * as ts from "typescript";

const dummyIdentifiers = [
"ClassName",
Expand Down
2 changes: 1 addition & 1 deletion generator/transformers/azure/transformer.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import * as ts from "typescript";
import { cloneDeep } from "lodash";
import * as ts from "typescript";

const dummyIdentifiers = [
"ClassName",
Expand Down
2 changes: 1 addition & 1 deletion generator/transformers/do/transformer.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import * as ts from "typescript";
import { cloneDeep } from "lodash";
import * as ts from "typescript";

const dummyIdentifiers = [
"ClassName",
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import * as ts from "typescript";
import { cloneDeep } from "lodash";
import * as ts from "typescript";

const dummyIdentifiers = [
"ClassName",
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import * as ts from "typescript";
import { cloneDeep } from "lodash";
import * as ts from "typescript";

const dummyIdentifiers = [
"ClassName",
Expand Down
6 changes: 5 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -37,9 +37,13 @@
"@types/lodash": "^4.14.158",
"@types/mocha": "^8.0.0",
"@types/node": "^14.0.6",
"@typescript-eslint/eslint-plugin": "^5.19.0",
"@typescript-eslint/parser": "^5.19.0",
"better-docs": "^2.3.0",
"chai": "^4.2.0",
"cross-env": "^7.0.2",
"eslint": "^8.13.0",
"eslint-plugin-simple-import-sort": "^7.0.0",
"husky": "^4.3.0",
"jsdoc": "^3.6.5",
"lerna": "^3.22.1",
Expand All @@ -51,7 +55,7 @@
},
"husky": {
"hooks": {
"pre-commit": "lerna run test && lerna run prettier",
"pre-commit": "lerna run test && lerna run prettier && lerna run lint",
"pre-push": "lerna run test"
}
}
Expand Down
Loading

0 comments on commit c859719

Please sign in to comment.