Skip to content

Commit

Permalink
(chore) update two common directories to eslint
Browse files Browse the repository at this point in the history
  • Loading branch information
anthonyvercolano committed Nov 13, 2022
1 parent 9f06146 commit 42d7588
Show file tree
Hide file tree
Showing 47 changed files with 1,872 additions and 1,573 deletions.
26 changes: 0 additions & 26 deletions .eslintrc.json

This file was deleted.

12 changes: 12 additions & 0 deletions common/core/.eslintignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
# don't ever lint node_modules
node_modules
# don't lint build output (make sure it's set to your correct build folder name)
dist
# don't lint nyc coverage output
coverage
# don't lint tests
# test
# don't lint generated code
pl
# don't use rules on the config file
.eslintrc.js
151 changes: 151 additions & 0 deletions common/core/.eslintrc.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,151 @@
module.exports = {
"env": {
"commonjs": true,
"node": true,
"mocha": true,
"es6": true
},
"extends": [
"eslint:recommended",
"plugin:security/recommended",
"plugin:mocha/recommended"
],
"plugins": [
"@typescript-eslint",
"mocha",
"jsdoc"
],
"parserOptions": {
"ecmaVersion": 8,
tsconfigRootDir: __dirname
},
"overrides": [
{
"files": ["*.ts"],
"parserOptions": {
"project": "tsconfig.json",
"sourceType": "module"
},
"extends": [
"plugin:@typescript-eslint/recommended",
// "plugin:@typescript-eslint/recommended-requiring-type-checking",
],
"rules": {
"@typescript-eslint/no-explicit-any": "off",
"@typescript-eslint/no-inferrable-types": "off",
"@typescript-eslint/no-namespace": "off",
"@typescript-eslint/member-ordering": ["error", { "default": ["abstract-method", "instance-method", "static-method"] }],
"@typescript-eslint/no-unused-vars": ["error", { "argsIgnorePattern": "^_", "varsIgnorePattern": "^_" }],
"@typescript-eslint/dot-notation": "error",
"@typescript-eslint/member-delimiter-style": [
"error",
{
"multiline": {
"delimiter": "semi",
"requireLast": true
},
"singleline": {
"delimiter": "semi",
"requireLast": false
}
}
],
"@typescript-eslint/typedef": [
"error",
{
"callSignature": true,
"parameter": true,
"propertyDeclaration": true,
"memberVariableDeclaration": true,
"arrowParameter": false
}
],
"@typescript-eslint/no-empty-function": "error",
"@typescript-eslint/no-unused-expressions": "error",
"@typescript-eslint/no-var-requires": "error",
"@typescript-eslint/semi": [
"error",
"always"
],
"@typescript-eslint/type-annotation-spacing": "error",
// "@typescript-eslint/no-dupe-class-members": "off",
}
},
],
"rules": {
"security/detect-object-injection": "off",
"mocha/no-setup-in-describe": "off",
"no-unused-vars": ["error", { "argsIgnorePattern": "^_", "varsIgnorePattern": "^_" }],
"arrow-parens": [
"error",
"always"
],
"brace-style": [
"error",
"1tbs",
{ "allowSingleLine": true }
],
"comma-dangle": "off",
"eol-last": "error",
"eqeqeq": [
"error",
"smart"
],
"id-blacklist": [
"error",
"any",
"Number",
"number",
"String",
"string",
"Boolean",
"boolean",
"Undefined",
"undefined"
],
"id-match": "error",
"jsdoc/check-alignment": "error",
"jsdoc/newline-after-description": "error",
"linebreak-style": "off",
"max-len": "off",
"new-parens": "error",
"no-empty": "error",
"no-fallthrough": "error",
"no-invalid-this": "error",
"no-new-wrappers": "error",
"no-null/no-null": "off",
"no-redeclare": "error",
"no-trailing-spaces": "error",
"no-unsafe-finally": "error",
"no-var": "error",
"object-curly-spacing": [
"error",
"always"
],
"one-var": [
"error",
"never"
],
"require-jsdoc": "off",
"space-before-function-paren": [
"error",
{
"anonymous": "always",
"named": "never"
}
],
// "spaced-comment": [
// "error",
// "always",
// {
// "markers": [
// "/"
// ],
// "block": {
// "balanced": true
// }
// }
// ],
"use-isnan": "error"
}
}
19 changes: 13 additions & 6 deletions common/core/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,27 +8,34 @@
"typings": "common.d.ts",
"dependencies": {
"async": "^3.2.3",
"es5-ext": "0.10.53",
"debug": "^4.3.1",
"getos": "^3.2.1"
},
"devDependencies": {
"@istanbuljs/nyc-config-typescript": "^1.0.1",
"@types/getos": "^3.0.0",
"@types/node": "^16.10.2",
"eslint": "^8.26.0",
"@typescript-eslint/eslint-plugin": "^5.41.0",
"@typescript-eslint/eslint-plugin-tslint": "^5.41.0",
"@typescript-eslint/parser": "^5.41.0",
"eslint-plugin-jsdoc": "^39.3.25",
"eslint-plugin-mocha": "^10.1.0",
"eslint-plugin-no-null": "^1.0.2",
"eslint-plugin-no-only-tests": "^3.1.0",
"eslint-plugin-promise": "^6.1.1",
"eslint-plugin-security": "^1.5.0",
"chai": "^4.3.3",
"mocha": "^9.2.1",
"nyc": "^15.0.0",
"sinon": "^11.1.2",
"source-map-support": "^0.5.16",
"ts-node": "^8.6.2",
"tslint": "^6.1.3",
"typescript": "4.4.4"
},
"scripts": {
"fakeScript": "000001",
"npmlockrefresh": "npm i --package-lock-only",
"lint": "tslint --project . -c ../../tslint.json",
"srclint": "eslint src --ext .ts -f visualstudio",
"tstlint": "eslint test --ext .js -f visualstudio",
"lint": "npm run srclint && npm run tstlint",
"build": "tsc",
"unittest-min": "tsc && nyc --reporter lcov ../../node_modules/mocha/bin/_mocha --reporter dot",
"alltest-min": "tsc && nyc --reporter lcov ../../node_modules/mocha/bin/_mocha --reporter dot test/_*_test*.js",
Expand Down
5 changes: 3 additions & 2 deletions common/core/src/authorization.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import * as crypto from 'crypto';
/**
* Returns the seconds elapsed since 1 January 1970 00:00:00 UTC until one
* hour from now.
*
* @function anHourFromNow
*/
export function anHourFromNow(): number {
Expand All @@ -21,7 +22,7 @@ export function anHourFromNow(): number {
export function encodeUriComponentStrict(str: string): string {
// this stricter version of encodeURIComponent is a recommendation straight out of the MDN docs, see:
// https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/encodeURIComponent#Description
return encodeURIComponent(str).replace(/[!'()*]/g, function(c: string): string {
return encodeURIComponent(str).replace(/[!'()*]/g, function (c: string): string {
return '%' + c.charCodeAt(0).toString(16);
});
}
Expand All @@ -34,7 +35,7 @@ export function stringToSign(resourceUri: string, expiry: string): string {
/*Codes_SRS_NODE_COMMON_AUTHORIZATION_05_005: [<signature> shall be an HMAC-SHA256 hash of <stringToSign>, which is then base64-encoded.]*/
/*Codes_SRS_NODE_COMMON_AUTHORIZATION_05_011: [The crypto algorithm should directly convert from base64 encoded password buffer to ensure JS compatibility]*/
export function hmacHash(password: string, stringToSign: string): string {
let hmac = crypto.createHmac('sha256', Buffer.from(password, 'base64'));
const hmac = crypto.createHmac('sha256', Buffer.from(password, 'base64'));
hmac.update(stringToSign);
return hmac.digest('base64');
}
Expand Down
9 changes: 9 additions & 0 deletions common/core/src/connection_string.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,55 +13,64 @@ import { ArgumentError } from './errors';
export class ConnectionString {
/**
* Hostname of the Azure IoT hub.
*
* @memberof {azure-iot-common.ConnectionString}
*/
// tslint:disable-next-line:variable-name
HostName?: string;
/**
* Unique device identifier as it exists in the device identity registry. This is only used for device connection strings.
*
* @memberof {azure-iot-common.ConnectionString}
*/
// tslint:disable-next-line:variable-name
DeviceId?: string;
/**
* Unique module identifier as it exists in the device identity registry. This is only used for device connection strings.
*
* @memberof {azure-iot-common.ConnectionString}
*/
// tslint:disable-next-line:variable-name
ModuleId?: string;
/**
* Symmetric key used to create shared access signature tokens that are in turn used to authenticate the connection. Associated either with a specific device or a specific service policy.
*
* @memberof {azure-iot-common.ConnectionString}
*/
// tslint:disable-next-line:variable-name
SharedAccessKey?: string;
/**
* Name of the access policy used to connect to the Azure IoT hub. used only in the case of the service SDK, unused with the Device SDK (which uses `DeviceId` instead).
*
* @memberof {azure-iot-common.ConnectionString}
*/
// tslint:disable-next-line:variable-name
SharedAccessKeyName?: string;
/**
* IP address or internet name of the host machine working as a device or protocol gateway. Used when communicating with Azure Edge devices.
*
* @memberof {azure-iot-common.ConnectionString}
*/
// tslint:disable-next-line:variable-name
GatewayHostName?: string;
/**
* A shared access signature which encapsulates "device connect" permissions on an IoT hub.
*
* @memberof {azure-iot-common.ConnectionString}
*/
// tslint:disable-next-line:variable-name
SharedAccessSignature?: string;
/**
* This property exists only if a device uses x509 certificates for authentication and if it exists, will be set to True.
*
* @memberof {azure-iot-common.ConnectionString}
*/
// tslint:disable-next-line:variable-name
x509?: string;

/**
* Parses a string and returns the corresponding {@link azure-iot-common.ConnectionString} object.
*
* @param {string} source string from which the connection string will be extracted
* @param {string[]} requiredFields array of strings listing the fields that are expected to be found.
*/
Expand Down
6 changes: 3 additions & 3 deletions common/core/src/dictionary.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,13 @@

/*Codes_SRS_NODE_COMMON_DICTIONARY_05_001: [The function createDictionary shall accept as arguments the source string and a field separator string.]*/
export function createDictionary(source: string, separator: string): createDictionary.Dictionary<string> {
let dict: createDictionary.Dictionary<string> = {};
const dict: createDictionary.Dictionary<string> = {};
/*Codes_SRS_NODE_COMMON_DICTIONARY_05_003: [createDictionary shall search the source string for elements of the form 'key=value', where the element is found either at the beginning of the source string, or immediately following an instance of the field separator string.]*/
/*Codes_SRS_NODE_COMMON_DICTIONARY_05_002: [createDictionary shall convert the source and separator arguments to type String before using them.]*/
/*Codes_SRS_NODE_COMMON_DICTIONARY_05_006: [If the source string is falsy, createDictionary shall return an object with no properties.]*/
const elems: string[] = String(source).split(String(separator));
const elements: string[] = String(source).split(String(separator));

elems.forEach(function (elem: string): void {
elements.forEach(function (elem: string): void {
const pos = elem.indexOf('=');
if (pos < 0) return;

Expand Down
2 changes: 1 addition & 1 deletion common/core/src/errors.ts
Original file line number Diff line number Diff line change
Expand Up @@ -168,7 +168,7 @@ export class MessageTooLargeError extends Error {
}

/**
* Error thrown when an internal server error occured. You may have found a bug?
* Error thrown when an internal server error occurred. You may have found a bug?
*
* @augments {Error}
*/
Expand Down
3 changes: 2 additions & 1 deletion common/core/src/message.ts
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,7 @@ export class Message {

/**
* Creates a new {@link azure-iot-common.Message} object
*
* @constructor
* @param data a Node [Buffer]{@link https://nodejs.org/api/globals.html#globals_class_buffer}
* object or anything that can be passed to the [Buffer]{@link https://nodejs.org/api/globals.html#globals_class_buffer} constructor
Expand Down Expand Up @@ -146,6 +147,6 @@ export class Message {
}

export namespace Message {
export type BufferConvertible = Buffer | String | any[] | ArrayBuffer;
export type BufferConvertible = Buffer | string | any[] | ArrayBuffer;

}
4 changes: 3 additions & 1 deletion common/core/src/properties.ts
Original file line number Diff line number Diff line change
Expand Up @@ -39,12 +39,13 @@ export class Properties {

/**
* Returns the key-value pair corresponding to the given index.
*
* @returns {Object} Key-value pair corresponding to the given index. The
* returned object has the properties `key` and `value`
* corresponding to the key and value of the property.
*/
/* Codes_SRS_NODE_IOTHUB_PROPERTIES_07_001: [if the supplied index is greater or equal to zero and the is less than property map length then it shall return the property object.] */
getItem(index: number): { key: string, value: string } {
getItem(index: number): { key: string; value: string } {
if (index >= 0 && index < this.propertyList.length)
return this.propertyList[index];

Expand All @@ -54,6 +55,7 @@ export class Properties {

/**
* Returns the value property of the element that has the given key.
*
* @returns {Object} corresponding value or undefined if the key doesn't exist.
*/
getValue(key: string): any {
Expand Down
Loading

0 comments on commit 42d7588

Please sign in to comment.