Skip to content

Commit ea84090

Browse files
authored
Merge pull request #39 from VKCOM/fix/quotes
fix: Quotes for properties with dash
2 parents e6b0a72 + 8ec311d commit ea84090

File tree

7 files changed

+2638
-781
lines changed

7 files changed

+2638
-781
lines changed

.eslintrc.json

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,16 @@
2222
"@typescript-eslint/explicit-member-accessibility": "off",
2323
"@typescript-eslint/no-unnecessary-condition": "off",
2424
"@typescript-eslint/no-magic-numbers": "off",
25-
"@typescript-eslint/no-extra-parens": "off"
26-
}
25+
"@typescript-eslint/no-extra-parens": "off",
26+
27+
"no-shadow": "off"
28+
},
29+
"overrides": [
30+
{
31+
"files": ["**/*.ts"],
32+
"rules": {
33+
"no-undef": "off"
34+
}
35+
}
36+
]
2737
}

jest.config.js

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
/** @type {import('ts-jest/dist/types').InitialOptionsTsJest} */
2+
module.exports = {
3+
preset: 'ts-jest',
4+
testEnvironment: 'node',
5+
};

package.json

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@
3333
"clear": "rimraf dist/*",
3434
"build": "yarn clear && tsc",
3535
"watch": "yarn clear && tsc --watch",
36-
"test": "tsc --noEmit && eslint src --ext .ts"
36+
"test": "jest && tsc --noEmit && eslint src --ext .ts"
3737
},
3838
"pre-commit": [
3939
"test"
@@ -43,15 +43,18 @@
4343
"chalk": "4.1.0"
4444
},
4545
"devDependencies": {
46+
"@types/jest": "^28.1.5",
4647
"@types/node": "^14.0.13",
47-
"@typescript-eslint/eslint-plugin": "2.34.0",
48-
"@typescript-eslint/parser": "2.0.0",
49-
"@vkontakte/eslint-config": "2.5.0",
50-
"eslint": "6.8.0",
51-
"eslint-plugin-react": "7.19.0",
52-
"eslint-plugin-react-hooks": "3.0.0",
48+
"@typescript-eslint/eslint-plugin": "5.30.6",
49+
"@typescript-eslint/parser": "5.30.6",
50+
"@vkontakte/eslint-config": "3.1.0",
51+
"eslint": "8.19.0",
52+
"eslint-plugin-react": "7.30.1",
53+
"eslint-plugin-react-hooks": "4.6.0",
54+
"jest": "28.1.3",
5355
"pre-commit": "1.2.2",
5456
"rimraf": "^3.0.2",
55-
"typescript": "3.9.5"
57+
"ts-jest": "^28.0.6",
58+
"typescript": "4.3.5"
5659
}
5760
}

src/generators/methods.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ export function normalizeMethodInfo(method: Schema.Method): NormalizeMethodInfoR
1818
// For method params "boolean" type means 1 or 0
1919
// Real "false" boolean value will be detected by API as true
2020
if (parameter.type === 'boolean') {
21+
// @ts-expect-error
2122
delete parameter.type;
2223
parameter.$ref = baseBoolIntRef;
2324
}

src/helpers.test.ts

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
import { areQuotesNeededForProperty } from './helpers';
2+
3+
test('areQuotesNeededForProperty', () => {
4+
expect(areQuotesNeededForProperty('user_id')).toBe(false);
5+
expect(areQuotesNeededForProperty('uuid4')).toBe(false);
6+
expect(areQuotesNeededForProperty('_foo')).toBe(false);
7+
8+
expect(areQuotesNeededForProperty('4uuid')).toBe(true);
9+
expect(areQuotesNeededForProperty('user-id')).toBe(true);
10+
expect(areQuotesNeededForProperty('user&id')).toBe(true);
11+
expect(areQuotesNeededForProperty('идентификатор')).toBe(true);
12+
});

src/helpers.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -111,9 +111,10 @@ export function areQuotesNeededForProperty(name: string | number): boolean {
111111
return false;
112112
}
113113

114-
if (/[&]/.test(name)) {
114+
if (/[&-]/.test(name)) {
115115
return true;
116116
}
117+
117118
return !(/^[a-z_]([a-z0-9_])+$/i.test(name) || /^[a-z_]/i.test(name));
118119
}
119120

0 commit comments

Comments
 (0)