Skip to content
This repository has been archived by the owner on Dec 15, 2023. It is now read-only.

Commit

Permalink
Fix lint issue and add eslint into compile (#110)
Browse files Browse the repository at this point in the history
Co-authored-by: FAREAST\renhel <[email protected]>
  • Loading branch information
lirenhe and FAREAST\renhel authored Jan 18, 2021
1 parent f7a7b53 commit 04f1a99
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 12 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
"start": "node dist/src/index.js",
"debug": "node --max_old_space_size=4096 --inspect-brk --inspect-port=9997 ./dist/src/index.js",
"eslint": "node_modules\\.bin\\eslint src/**/*.*",
"build": "tsc -p .",
"build": "npm run eslint && tsc -p .",
"start-testserver": "./node_modules/.bin/start-autorest-testserver",
"stop-testserver": "./node_modules/.bin/stop-autorest-testserver",
"watch": "tsc -p . --watch",
Expand Down
22 changes: 11 additions & 11 deletions src/helper.ts
Original file line number Diff line number Diff line change
Expand Up @@ -644,7 +644,7 @@ export class Helper {
if (!enumExample || isNullOrUndefined(op.extensions?.['x-ms-examples'])) return;
const cliKeyMissing = '<clikey-missing>';

for (let exampleName of Object.getOwnPropertyNames(op.extensions['x-ms-examples'])) {
for (const exampleName of Object.getOwnPropertyNames(op.extensions['x-ms-examples'])) {
const example = op.extensions['x-ms-examples'][exampleName];
paths.push(`['${exampleName}']`);
action({
Expand Down Expand Up @@ -917,20 +917,20 @@ export class Helper {
return m4Path;
}

public static setPathValue (obj, path, value) {
public static setPathValue(obj, path, value) {
if (Object(obj) !== obj) return obj; // When obj is not an object
// If not yet an array, get the keys from the string-path
if (!Array.isArray(path)) path = path.toString().match(/[^.[\]]+/g) || [];
path.slice(0,-1).reduce((a, c, i) => // Iterate all of them except the last one
Object(a[c]) === a[c] // Does the key exist and is its value an object?
// Yes: then follow that path
? a[c]
// No: create the key. Is the next key a potential array-index?
: a[c] = Math.abs(path[i+1])>>0 === +path[i+1]
? [] // Yes: assign a new array object
: {}, // No: assign a new plain object
obj)[path[path.length-1]] = value; // Finally assign the value to the last key
Object(a[c]) === a[c] // Does the key exist and is its value an object?
// Yes: then follow that path
? a[c]
// No: create the key. Is the next key a potential array-index?
: a[c] = Math.abs(path[i+1])>>0 === +path[i+1]
? [] // Yes: assign a new array object
: {}, // No: assign a new plain object
obj)[path[path.length-1]] = value; // Finally assign the value to the last key
return obj; // Return the top-level object to allow chaining
};
}

}

0 comments on commit 04f1a99

Please sign in to comment.