Socket
Socket
Sign inDemoInstall

bob-group-frontend-coding-standards

Package Overview
Dependencies
Maintainers
0
Versions
6
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

bob-group-frontend-coding-standards - npm Package Compare versions

Comparing version 1.0.4 to 1.0.5

45

dist/index.js

@@ -43,2 +43,3 @@ "use strict";

forgottenTodos: [],
missingPropTypes: [],
};

@@ -70,2 +71,3 @@ let allImportNames = [];

data = listMissingFontawesomeImports(data);
data = fixIProps(data);
// // data = makeCommentsSentenceCase(data); // todo needs more testing

@@ -88,2 +90,3 @@ /* --------------------------------*/

}
checkIfPropsHaveType(data, file, filePath);
fs.writeFile(filePath, data, "utf8", (err) => {

@@ -211,2 +214,17 @@ if (err) {

}
function checkIfPropsHaveType(data, file, filePath) {
try {
const componentName = utils.getComponentName(data);
const propString = `${componentName}(props: any)`;
if (data.indexOf(propString) > -1) {
warnings.missingPropTypes.push({
file,
error: "No type definition for props (props: any)",
});
}
}
catch (e) {
utils.writeOutput("error", `Could not check component prop type: ${e}`);
}
}
function checkStateVariableNamingConventions(data, file, filePath) {

@@ -311,2 +329,29 @@ try {

}
function fixIProps(data) {
try {
let componentName = utils.getComponentName(data);
const regex = new RegExp(`function ${componentName}\\s*\\(props:\\s*\\{[\\n\\sa-zA-z?:;()|&=>,{}?]*}\\) {`, "m");
const match = data.match(regex);
if (match) {
let propsObject = match[0].trim();
propsObject = propsObject
.split(`function ${componentName}(props:`)
.join("")
.split(") {")
.join("");
const iProps = `interface IProps ${propsObject}\n\n`;
let newData = data.replace(propsObject, "IProps");
let functionIndex = data.indexOf(`export default function ${componentName}`);
if (functionIndex === -1) {
functionIndex = data.indexOf(`function ${componentName}`);
}
newData = utils.insertSubstring(newData, iProps, functionIndex);
data = newData;
}
}
catch (e) {
utils.writeOutput("error", `Could not fix IProps: ${e}`);
}
return data;
}
function makeCommentsSentenceCase(data) {

@@ -313,0 +358,0 @@ // CRITERIA: All comments should be sentence case

16

dist/src/utils.js
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.getFontawesomeImportNames = exports.getVariables = exports.getStateVariables = exports.logErrors = exports.getComponentName = exports.getInterfaceName = exports.isComponentFile = exports.isInterfaceFile = exports.writeOutput = exports.kebabToUpperCase = exports.keyToHumanReadable = exports.upperSnakeCaseRegex = exports.upperCamelCaseRegex = exports.camelCaseRegex = void 0;
exports.insertSubstring = exports.getFontawesomeImportNames = exports.getVariables = exports.getStateVariables = exports.logErrors = exports.getComponentName = exports.getInterfaceName = exports.isComponentFile = exports.isInterfaceFile = exports.writeOutput = exports.kebabToUpperCase = exports.keyToHumanReadable = exports.upperSnakeCaseRegex = exports.upperCamelCaseRegex = exports.camelCaseRegex = void 0;
const camelCaseRegex = /^[a-z][A-Za-z0-9]*$/;

@@ -105,3 +105,3 @@ exports.camelCaseRegex = camelCaseRegex;

function getVariables(data) {
const variableRegex = /\b(?:let|const|var)\s+([a-zA-Z_$][a-zA-Z0-9_$]*)\b/g;
const variableRegex = /\b(?:let|const|var)\s+([a-zA-Z_$][a-zA-Z0-9_$]*)\b(?!\s*=\s*(?:lazy\(|createContext|require))/g;
const variableNames = [];

@@ -127,1 +127,13 @@ let match;

exports.getFontawesomeImportNames = getFontawesomeImportNames;
function insertSubstring(originalString, insertString, position) {
if (position < 0) {
position = 0;
}
if (position > originalString.length) {
position = originalString.length;
}
const before = originalString.slice(0, position);
const after = originalString.slice(position);
return before + insertString + after;
}
exports.insertSubstring = insertSubstring;

@@ -47,2 +47,3 @@ const fs = require("fs");

forgottenTodos: IErrorObject[];
missingPropTypes: IErrorObject[];
} = {

@@ -56,2 +57,3 @@ filesMissingRenderFunction: [],

forgottenTodos: [],
missingPropTypes: [],
};

@@ -86,2 +88,3 @@

data = listMissingFontawesomeImports(data);
data = fixIProps(data);
// // data = makeCommentsSentenceCase(data); // todo needs more testing

@@ -105,2 +108,3 @@

}
checkIfPropsHaveType(data, file, filePath);
fs.writeFile(filePath, data, "utf8", (err: any) => {

@@ -244,2 +248,17 @@ if (err) {

function checkIfPropsHaveType(data: string, file: string, filePath: string) {
try {
const componentName = utils.getComponentName(data);
const propString = `${componentName}(props: any)`;
if (data.indexOf(propString) > -1) {
warnings.missingPropTypes.push({
file,
error: "No type definition for props (props: any)",
});
}
} catch (e) {
utils.writeOutput("error", `Could not check component prop type: ${e}`);
}
}
function checkStateVariableNamingConventions(

@@ -383,2 +402,38 @@ data: string,

function fixIProps(data: string) {
try {
let componentName = utils.getComponentName(data);
const regex = new RegExp(
`function ${componentName}\\s*\\(props:\\s*\\{[\\n\\sa-zA-z?:;()|&=>,{}?]*}\\) {`,
"m"
);
const match = data.match(regex);
if (match) {
let propsObject = match[0].trim();
propsObject = propsObject
.split(`function ${componentName}(props:`)
.join("")
.split(") {")
.join("");
const iProps = `interface IProps ${propsObject}\n\n`;
let newData = data.replace(propsObject, "IProps");
let functionIndex = data.indexOf(
`export default function ${componentName}`
);
if (functionIndex === -1) {
functionIndex = data.indexOf(`function ${componentName}`);
}
newData = utils.insertSubstring(newData, iProps, functionIndex);
data = newData;
}
} catch (e) {
utils.writeOutput("error", `Could not fix IProps: ${e}`);
}
return data;
}
function makeCommentsSentenceCase(data: string) {

@@ -385,0 +440,0 @@ // CRITERIA: All comments should be sentence case

2

package.json
{
"name": "bob-group-frontend-coding-standards",
"version": "1.0.4",
"version": "1.0.5",
"description": "Script to check that frontend code follows coding standards",

@@ -5,0 +5,0 @@ "main": "dist/index.js",

@@ -122,4 +122,5 @@ const camelCaseRegex = /^[a-z][A-Za-z0-9]*$/;

function getVariables(data: string) {
const variableRegex = /\b(?:let|const|var)\s+([a-zA-Z_$][a-zA-Z0-9_$]*)\b/g;
const variableRegex = /\b(?:let|const|var)\s+([a-zA-Z_$][a-zA-Z0-9_$]*)\b(?!\s*=\s*(?:lazy\(|createContext|require))/g;
const variableNames = [];

@@ -147,2 +148,16 @@ let match;

function insertSubstring(originalString: string, insertString: string, position: number) {
if (position < 0) {
position = 0;
}
if (position > originalString.length) {
position = originalString.length;
}
const before = originalString.slice(0, position);
const after = originalString.slice(position);
return before + insertString + after;
}
export {

@@ -163,2 +178,3 @@ camelCaseRegex,

getFontawesomeImportNames,
insertSubstring
};
SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc