Skip to content

Commit

Permalink
Snake case variable detection
Browse files Browse the repository at this point in the history
  • Loading branch information
michelcaradec committed Nov 11, 2019
1 parent 35777ba commit d06c08a
Show file tree
Hide file tree
Showing 5 changed files with 18 additions and 3 deletions.
7 changes: 7 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,13 @@ Here are a few common issues.

## [Unreleased]

## [0.1.2] - 2019-11-11

### Added

- Code provider:
- Snake case variable detection.

## [0.1.1] - 2019-11-09

### Added
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
"url": "https://github.com/michelcaradec/string-checker-js"
},
"license": "MIT",
"version": "0.1.1",
"version": "0.1.2",
"engines": {
"vscode": "^1.38.0"
},
Expand Down
6 changes: 5 additions & 1 deletion src/checker/providers/codeDetect.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import * as vscode from 'vscode';
import { IDetectProvider } from "./detectProvider";
import { ConfidenceLevel, StatsEventType } from "../../enumerations";
import { Constants, ProviderName } from '../../constants';
import { isCamelCase, isPascalCase, getNonAlphaRatio } from '../../helpers/utils';
import { isCamelCase, isPascalCase, getNonAlphaRatio, isSnakeCase } from '../../helpers/utils';

export class CodeDetect implements IDetectProvider {
private _minWordLength: number;
Expand Down Expand Up @@ -118,6 +118,10 @@ export class CodeDetect implements IDetectProvider {
if (isPascalCase(text)) {
return [ConfidenceLevel.Technical, 'PascalCase'];
}

if (isSnakeCase(text)) {
return [ConfidenceLevel.Technical, 'snake_case'];
}
} else {
if (text.split(' ').some(w => w.length > this._maxWordLength)) {
// Some words (no white space) too long to be a sentence => technical string.
Expand Down
2 changes: 1 addition & 1 deletion src/constants.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
export class Constants {
static readonly ExtensionName = 'string-checker-js';
static readonly ExtensionNameHumanReadable = 'String Checker JS';
static readonly ExtensionVersion = 'v0.1.1';
static readonly ExtensionVersion = 'v0.1.2';
static readonly ExtensionID = 'string-checker-js';
static readonly ItemStringPrefix = 'string:';
static readonly ItemRegexPrefix = 'regex:';
Expand Down
4 changes: 4 additions & 0 deletions src/helpers/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,10 @@ export function isPascalCase(text: string): boolean {
return /^([A-Z][^\sA-Z]+)+$/.test(text);
}

export function isSnakeCase(text: string): boolean {
return /^[a-z]([a-z\d]|_)+$/i.test(text);
}

export function getNonAlphaRatio(text: string | undefined): number {
if ((text?.length ?? 0) <= 0) {
return 0;
Expand Down

0 comments on commit d06c08a

Please sign in to comment.