Skip to content

Commit d06c08a

Browse files
committed
Snake case variable detection
1 parent 35777ba commit d06c08a

File tree

5 files changed

+18
-3
lines changed

5 files changed

+18
-3
lines changed

CHANGELOG.md

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,13 @@ Here are a few common issues.
1111

1212
## [Unreleased]
1313

14+
## [0.1.2] - 2019-11-11
15+
16+
### Added
17+
18+
- Code provider:
19+
- Snake case variable detection.
20+
1421
## [0.1.1] - 2019-11-09
1522

1623
### Added

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
"url": "https://github.com/michelcaradec/string-checker-js"
1010
},
1111
"license": "MIT",
12-
"version": "0.1.1",
12+
"version": "0.1.2",
1313
"engines": {
1414
"vscode": "^1.38.0"
1515
},

src/checker/providers/codeDetect.ts

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import * as vscode from 'vscode';
22
import { IDetectProvider } from "./detectProvider";
33
import { ConfidenceLevel, StatsEventType } from "../../enumerations";
44
import { Constants, ProviderName } from '../../constants';
5-
import { isCamelCase, isPascalCase, getNonAlphaRatio } from '../../helpers/utils';
5+
import { isCamelCase, isPascalCase, getNonAlphaRatio, isSnakeCase } from '../../helpers/utils';
66

77
export class CodeDetect implements IDetectProvider {
88
private _minWordLength: number;
@@ -118,6 +118,10 @@ export class CodeDetect implements IDetectProvider {
118118
if (isPascalCase(text)) {
119119
return [ConfidenceLevel.Technical, 'PascalCase'];
120120
}
121+
122+
if (isSnakeCase(text)) {
123+
return [ConfidenceLevel.Technical, 'snake_case'];
124+
}
121125
} else {
122126
if (text.split(' ').some(w => w.length > this._maxWordLength)) {
123127
// Some words (no white space) too long to be a sentence => technical string.

src/constants.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
export class Constants {
22
static readonly ExtensionName = 'string-checker-js';
33
static readonly ExtensionNameHumanReadable = 'String Checker JS';
4-
static readonly ExtensionVersion = 'v0.1.1';
4+
static readonly ExtensionVersion = 'v0.1.2';
55
static readonly ExtensionID = 'string-checker-js';
66
static readonly ItemStringPrefix = 'string:';
77
static readonly ItemRegexPrefix = 'regex:';

src/helpers/utils.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,10 @@ export function isPascalCase(text: string): boolean {
4040
return /^([A-Z][^\sA-Z]+)+$/.test(text);
4141
}
4242

43+
export function isSnakeCase(text: string): boolean {
44+
return /^[a-z]([a-z\d]|_)+$/i.test(text);
45+
}
46+
4347
export function getNonAlphaRatio(text: string | undefined): number {
4448
if ((text?.length ?? 0) <= 0) {
4549
return 0;

0 commit comments

Comments
 (0)