Skip to content

Commit

Permalink
Merge pull request Azure#1 from arpanlaha/ts
Browse files Browse the repository at this point in the history
Port to TypeScript
  • Loading branch information
arpanlaha authored Jun 10, 2019
2 parents 0161711 + af06c8d commit 5da61a4
Show file tree
Hide file tree
Showing 34 changed files with 367 additions and 307 deletions.
1 change: 1 addition & 0 deletions .eslintrc.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,5 +13,6 @@
"ecmaVersion": 2018,
"sourceType": "module"
},
"parser": "@typescript-eslint/parser",
"rules": {}
}
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
node_modules
dist
package-lock.json
yarn.lock
.DS_Store
Expand Down
53 changes: 0 additions & 53 deletions lib/index.js

This file was deleted.

14 changes: 8 additions & 6 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,28 +11,30 @@
"eslint-plugin-azure"
],
"author": "Arpan Laha",
"main": "lib/index.js",
"main": "dist/src/index.js",
"scripts": {
"test": "mocha tests --recursive"
"test": "ts-mocha -p tsconfig.json tests/**/*.ts"
},
"repository": {
"type": "git",
"url": "https://github.com/arpanlaha/eslint-plugin-azure"
},
"dependencies": {
"requireindex": "~1.1.0",
"typescript": "<3.5.1"
},
"devDependencies": {
"@types/eslint": "^4.16.6",
"@types/estree": "0.0.39",
"@typescript-eslint/eslint-plugin": "^1.9.0",
"@typescript-eslint/experimental-utils": "^1.9.0",
"@typescript-eslint/parser": "^1.9.0",
"@typescript-eslint/typescript-estree": "^1.9.0",
"eslint": "^5.16.0",
"mocha": "^3.1.2",
"prettier": "^1.17.1"
"mocha": "^6.1.4",
"ts-mocha": "^6.0.0"
},
"engines": {
"node": ">=0.10.0"
},
"license": "ISC"
"license": "MIT"
}
20 changes: 20 additions & 0 deletions src/configs.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
export const configs = {
recommended: {
plugins: ["azure"],
env: ["node"],
parser: "@typescript-eslint/parser",
rules: {
"azure/ts-config-allowsyntheticdefaultimports": "error",
"azure/ts-config-declaration": "error",
"azure/ts-config-esmoduleinterop": "error",
"azure/ts-config-forceconsistentcasinginfilenames": "error",
"azure/ts-config-importhelpers": "error",
"azure/ts-config-isolatedmodules": "warning",
"azure/ts-config-module": "error",
"azure/ts-config-no-experimentaldecorators": "error",
"azure/ts-config-strict": "error",
"azure/ts-package-json-repo": "error",
"azure/ts-package-json-bugs": "error"
}
}
};
18 changes: 18 additions & 0 deletions src/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
/**
* @fileoverview Linting rules for the JavaScript/TypeScript Azure SDK
* @author Arpan Laha
*/

//------------------------------------------------------------------------------
// Requirements
//------------------------------------------------------------------------------

import { rules } from "./rules";
import { processors } from "./processors";
import { configs } from "./configs";

//------------------------------------------------------------------------------
// Plugin Definition
//------------------------------------------------------------------------------

export { rules, processors, configs };
16 changes: 16 additions & 0 deletions src/processors.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
/**
* @fileoverview Definition of processors
* @author Arpan Laha
*/

export const processors = {
".json": {
preprocess: function(text: string): string[] {
const code = "const json = " + text;
return [code];
},
postprocess: function(messages: string[][]): string[] {
return messages[0];
}
}
};
30 changes: 30 additions & 0 deletions src/rules/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
/**
* @fileoverview All rules
* @author Arpan Laha
*/

import { rule as tsConfigAllowSyntheticDefaultImports } from "./ts-config-allowsyntheticdefaultimports";
import { rule as tsConfigDeclaration } from "./ts-config-declaration";
import { rule as tsConfigEsModuleInterop } from "./ts-config-esmoduleinterop";
import { rule as tsConfigForceConsistentCasingInFileNames } from "./ts-config-forceconsistentcasinginfilenames";
import { rule as tsConfigImportHelpers } from "./ts-config-importhelpers";
import { rule as tsConfigIsolatedModules } from "./ts-config-isolatedmodules";
import { rule as tsConfigModule } from "./ts-config-module";
import { rule as tsConfigNoExperimentalDecorators } from "./ts-config-no-experimentaldecorators";
import { rule as tsConfigStrict } from "./ts-config-strict";
import { rule as tsPackageJsonBugs } from "./ts-package-json-bugs";
import { rule as tsPackageJsonRepo } from "./ts-package-json-repo";

export const rules = {
"ts-config-allowsyntheticdefaultimports": tsConfigAllowSyntheticDefaultImports,
"ts-config-declaration": tsConfigDeclaration,
"ts-config-esmoduleinterop": tsConfigEsModuleInterop,
"ts-config-forceconsistentcasinginfilenames": tsConfigForceConsistentCasingInFileNames,
"ts-config-importhelpers": tsConfigImportHelpers,
"ts-config-isolatedmodules": tsConfigIsolatedModules,
"ts-config-module": tsConfigModule,
"ts-config-noexperimentaldecorators": tsConfigNoExperimentalDecorators,
"ts-config-strict": tsConfigStrict,
"ts-package-json-bugs": tsPackageJsonBugs,
"ts-package-json-repo": tsPackageJsonRepo
};
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,14 @@
* @author Arpan Laha
*/

"use strict";

var structure = require("../utils/structure");
import { structure } from "../utils/structure";
import { Rule } from "eslint";

//------------------------------------------------------------------------------
// Rule Definition
//------------------------------------------------------------------------------

module.exports = {
export const rule = {
meta: {
type: "problem",

Expand All @@ -23,10 +22,9 @@ module.exports = {
url:
"https://azuresdkspecs.z5.web.core.windows.net/TypeScriptSpec.html#ts-config-allowsyntheticdefaultimports"
},
fixable: "code",
schema: [] // no options
},
create: function(context) {
create: function(context: Rule.RuleContext) {
var checkers = structure(context, {
outer: "compilerOptions",
inner: "allowSyntheticDefaultImports",
Expand All @@ -45,6 +43,6 @@ module.exports = {
// check the node corresponding to compilerOptions.allowSyntheticDefaultImports to see if it is set to true
"VariableDeclarator > ObjectExpression > Property[key.value='compilerOptions'] > ObjectExpression > Property[key.value='allowSyntheticDefaultImports']":
checkers.innerMatchesExpected
};
} as Rule.RuleListener;
}
};
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,14 @@
* @author Arpan Laha
*/

"use strict";

var structure = require("../utils/structure");
import { structure } from "../utils/structure";
import { Rule } from "eslint";

//------------------------------------------------------------------------------
// Rule Definition
//------------------------------------------------------------------------------

module.exports = {
export const rule = {
meta: {
type: "problem",

Expand All @@ -23,10 +22,9 @@ module.exports = {
url:
"https://azuresdkspecs.z5.web.core.windows.net/TypeScriptSpec.html#ts-config-declaration"
},
fixable: "code",
schema: [] // no options
},
create: function(context) {
create: function(context: Rule.RuleContext) {
var checkers = structure(context, {
outer: "compilerOptions",
inner: "declaration",
Expand All @@ -45,6 +43,6 @@ module.exports = {
// check the node corresponding to compilerOptions.declaration to see if it is set to true
"VariableDeclarator > ObjectExpression > Property[key.value='compilerOptions'] > ObjectExpression > Property[key.value='declaration']":
checkers.innerMatchesExpected
};
} as Rule.RuleListener;
}
};
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,14 @@

"use strict";

var structure = require("../utils/structure");
import { structure } from "../utils/structure";
import { Rule } from "eslint";

//------------------------------------------------------------------------------
// Rule Definition
//------------------------------------------------------------------------------

module.exports = {
export const rule = {
meta: {
type: "problem",

Expand All @@ -23,10 +24,9 @@ module.exports = {
url:
"https://azuresdkspecs.z5.web.core.windows.net/TypeScriptSpec.html#ts-config-esmoduleinterop"
},
fixable: "code",
schema: [] // no options
},
create: function(context) {
create: function(context: Rule.RuleContext) {
var checkers = structure(context, {
outer: "compilerOptions",
inner: "esModuleInterop",
Expand All @@ -45,6 +45,6 @@ module.exports = {
// check the node corresponding to compilerOptions.esModuleInterop to see if it is set to true
"VariableDeclarator > ObjectExpression > Property[key.value='compilerOptions'] > ObjectExpression > Property[key.value='esModuleInterop']":
checkers.innerMatchesExpected
};
} as Rule.RuleListener;
}
};
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,14 @@
* @author Arpan Laha
*/

"use strict";

var structure = require("../utils/structure");
import { structure } from "../utils/structure";
import { Rule } from "eslint";

//------------------------------------------------------------------------------
// Rule Definition
//------------------------------------------------------------------------------

module.exports = {
export const rule = {
meta: {
type: "problem",

Expand All @@ -23,10 +22,9 @@ module.exports = {
url:
"https://azuresdkspecs.z5.web.core.windows.net/TypeScriptSpec.html#ts-config-forceConsistentCasingInFileNames"
},
fixable: "code",
schema: [] // no options
},
create: function(context) {
create: function(context: Rule.RuleContext) {
var checkers = structure(context, {
outer: "compilerOptions",
inner: "forceConsistentCasingInFileNames",
Expand All @@ -45,6 +43,6 @@ module.exports = {
// check the node corresponding to compilerOptions.forceConsistentCasingInFileNames to see if it is set to true
"VariableDeclarator > ObjectExpression > Property[key.value='compilerOptions'] > ObjectExpression > Property[key.value='forceConsistentCasingInFileNames']":
checkers.innerMatchesExpected
};
} as Rule.RuleListener;
}
};
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,14 @@
* @author Arpan Laha
*/

"use strict";

var structure = require("../utils/structure");
import { structure } from "../utils/structure";
import { Rule } from "eslint";

//------------------------------------------------------------------------------
// Rule Definition
//------------------------------------------------------------------------------

module.exports = {
export const rule = {
meta: {
type: "problem",

Expand All @@ -23,10 +22,9 @@ module.exports = {
url:
"https://azuresdkspecs.z5.web.core.windows.net/TypeScriptSpec.html#ts-config-importhelpers"
},
fixable: "code",
schema: [] // no options
},
create: function(context) {
create: function(context: Rule.RuleContext) {
var checkers = structure(context, {
outer: "compilerOptions",
inner: "importHelpers",
Expand All @@ -45,6 +43,6 @@ module.exports = {
// check the node corresponding to compilerOptions.importHelpers to see if it is set to true
"VariableDeclarator > ObjectExpression > Property[key.value='compilerOptions'] > ObjectExpression > Property[key.value='importHelpers']":
checkers.innerMatchesExpected
};
} as Rule.RuleListener;
}
};
Loading

0 comments on commit 5da61a4

Please sign in to comment.