bob-group-frontend-coding-standards
Advanced tools
Comparing version 1.0.0 to 1.0.1
21
index.js
@@ -37,4 +37,5 @@ "use strict"; | ||
}; | ||
const camelCaseRegex = /^[a-z][A-Za-z]*$/; | ||
const upperCamelCaseRegex = /^[A-Z][A-Za-z]*$/; | ||
const camelCaseRegex = /^[a-z][A-Za-z0-9]*$/; | ||
const upperCamelCaseRegex = /^[A-Z][A-Za-z0-9]*$/; | ||
const upperSnakeCaseRegex = /^[A-Z0-9_]+$/; | ||
function writeOutput(type, content) { | ||
@@ -55,2 +56,4 @@ let colors = { | ||
!isInterfaceFile(filePath) && | ||
(filePath.indexOf("/pages/") > -1 || | ||
filePath.indexOf("/components/") > -1) && | ||
data.indexOf("function render") > -1); | ||
@@ -79,3 +82,3 @@ } | ||
// Checks for files | ||
// checkVariableNamingConventions(data, filePath); // todo needs testing | ||
checkVariableNamingConventions(data, file, filePath); | ||
checkForRenderFunction(data, filePath); | ||
@@ -191,5 +194,4 @@ checkForBooleanTruthyDetection(data, filePath); | ||
} | ||
function checkVariableNamingConventions(data, filePath) { | ||
// CRITERIA: Variables should be camel case | ||
// Todo: needs work - some consts are SOME_CONSTANT | ||
function checkVariableNamingConventions(data, file, filePath) { | ||
// CRITERIA: Variables should be camel case or upper snake case | ||
const variableRegex = /\b(?:let|const|var)\s+([a-zA-Z_$][a-zA-Z0-9_$]*)\b/g; | ||
@@ -202,3 +204,6 @@ const variableNames = []; | ||
variableNames.forEach((variableName) => { | ||
if (!camelCaseRegex.test(variableName)) { | ||
if (!camelCaseRegex.test(variableName) && | ||
!upperSnakeCaseRegex.test(variableName) && | ||
variableName !== file.split(".tsx").join("") && | ||
!(filePath.includes("/Routes") && variableName.includes("Page"))) { | ||
warnings.incorrectlyNamedVariables.push({ | ||
@@ -289,3 +294,3 @@ file: filePath, | ||
warnings.incorrectlyNamedVariables.length > 0 && | ||
logErrors("warning", "Variables that are not camel case", warnings.incorrectlyNamedVariables); | ||
logErrors("warning", "Variables that are not camel case or upper snake case", warnings.incorrectlyNamedVariables); | ||
warnings.incorrectTruthy.length > 0 && | ||
@@ -292,0 +297,0 @@ logErrors("warning", "Prefer boolean truthy detection Boolean(x) over double !!", warnings.incorrectTruthy); |
27
index.ts
@@ -47,4 +47,5 @@ const fs = require("fs"); | ||
const camelCaseRegex = /^[a-z][A-Za-z]*$/; | ||
const upperCamelCaseRegex = /^[A-Z][A-Za-z]*$/; | ||
const camelCaseRegex = /^[a-z][A-Za-z0-9]*$/; | ||
const upperCamelCaseRegex = /^[A-Z][A-Za-z0-9]*$/; | ||
const upperSnakeCaseRegex = /^[A-Z0-9_]+$/; | ||
@@ -72,2 +73,4 @@ function writeOutput( | ||
!isInterfaceFile(filePath) && | ||
(filePath.indexOf("/pages/") > -1 || | ||
filePath.indexOf("/components/") > -1) && | ||
data.indexOf("function render") > -1 | ||
@@ -100,3 +103,3 @@ ); | ||
// Checks for files | ||
// checkVariableNamingConventions(data, filePath); // todo needs testing | ||
checkVariableNamingConventions(data, file, filePath); | ||
checkForRenderFunction(data, filePath); | ||
@@ -232,5 +235,8 @@ checkForBooleanTruthyDetection(data, filePath); | ||
function checkVariableNamingConventions(data: string, filePath: string) { | ||
// CRITERIA: Variables should be camel case | ||
// Todo: needs work - some consts are SOME_CONSTANT | ||
function checkVariableNamingConventions( | ||
data: string, | ||
file: string, | ||
filePath: string | ||
) { | ||
// CRITERIA: Variables should be camel case or upper snake case | ||
const variableRegex = /\b(?:let|const|var)\s+([a-zA-Z_$][a-zA-Z0-9_$]*)\b/g; | ||
@@ -246,3 +252,8 @@ | ||
variableNames.forEach((variableName) => { | ||
if (!camelCaseRegex.test(variableName)) { | ||
if ( | ||
!camelCaseRegex.test(variableName) && | ||
!upperSnakeCaseRegex.test(variableName) && | ||
variableName !== file.split(".tsx").join("") && | ||
!(filePath.includes("/Routes") && variableName.includes("Page")) | ||
) { | ||
warnings.incorrectlyNamedVariables.push({ | ||
@@ -377,3 +388,3 @@ file: filePath, | ||
"warning", | ||
"Variables that are not camel case", | ||
"Variables that are not camel case or upper snake case", | ||
warnings.incorrectlyNamedVariables | ||
@@ -380,0 +391,0 @@ ); |
{ | ||
"name": "bob-group-frontend-coding-standards", | ||
"version": "1.0.0", | ||
"version": "1.0.1", | ||
"description": "Script to check that frontend code follows coding standards", | ||
@@ -5,0 +5,0 @@ "main": "index.js", |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
28738
695