chore: repo wide lint fixes

This commit is contained in:
Bijin A B
2025-12-03 09:44:50 +05:30
parent 4a38f2d49f
commit 62cf4139d7
460 changed files with 6921 additions and 7052 deletions

View File

@@ -33,17 +33,16 @@ const createRedirectConfig = (error, redirectUrl) => {
if (METHOD_CHANGING_REDIRECTS.includes(statusCode) && originalMethod !== 'head') {
requestConfig.method = 'get';
requestConfig.data = undefined;
// Clean up headers that are no longer relevant
delete requestConfig.headers['content-length'];
delete requestConfig.headers['Content-Length'];
delete requestConfig.headers['content-type'];
delete requestConfig.headers['content-type'];
delete requestConfig.headers['Content-Type'];
} else {
// For 307, 308 and other status codes: preserve method and body
if (requestConfig.data && typeof requestConfig.data === 'object' &&
requestConfig.data.constructor && requestConfig.data.constructor.name === 'FormData') {
if (requestConfig.data && typeof requestConfig.data === 'object'
&& requestConfig.data.constructor && requestConfig.data.constructor.name === 'FormData') {
const formData = requestConfig.data;
if (formData._released || (formData._streams && formData._streams.length === 0)) {
if (error.config._originalMultipartData && error.config.collectionPath) {
@@ -51,7 +50,7 @@ const createRedirectConfig = (error, redirectUrl) => {
requestConfig.data = recreatedForm;
const formHeaders = recreatedForm.getHeaders();
Object.assign(requestConfig.headers, formHeaders);
// preserve the original data for potential future redirects
requestConfig._originalMultipartData = error.config._originalMultipartData;
requestConfig.collectionPath = error.config.collectionPath;
@@ -80,7 +79,7 @@ function makeAxiosInstance({ requestMaxRedirects = 5, disableCookies } = {}) {
proxy: false,
maxRedirects: 0,
headers: {
"User-Agent": `bruno-runtime/${CLI_VERSION}`
'User-Agent': `bruno-runtime/${CLI_VERSION}`
}
});
@@ -133,7 +132,7 @@ function makeAxiosInstance({ requestMaxRedirects = 5, disableCookies } = {}) {
redirectUrl = URL.resolve(error.config.url, locationHeader);
}
if (!disableCookies){
if (!disableCookies) {
saveCookies(error.config.url, error.response.headers);
}

View File

@@ -1,5 +1,5 @@
const _ = require('lodash');
const {
const {
parseRequest: _parseRequest,
parseCollection: _parseCollection
} = require('@usebruno/filestore');
@@ -24,7 +24,7 @@ const collectionBruToJson = (bru) => {
const sequence = _.get(json, 'meta.seq');
if (json?.meta) {
transformedJson.meta = {
name: json.meta.name,
name: json.meta.name
};
if (sequence) {
@@ -94,11 +94,11 @@ const bruToJson = (bru) => {
if (requestType === 'grpc-request') {
const selectedMethod = _.get(json, 'grpc.method');
if(selectedMethod) transformedJson.request.method = selectedMethod;
if (selectedMethod) transformedJson.request.method = selectedMethod;
const selectedMethodType = _.get(json, 'grpc.methodType');
if(selectedMethodType) transformedJson.request.methodType = selectedMethodType;
if (selectedMethodType) transformedJson.request.methodType = selectedMethodType;
const protoPath = _.get(json, 'grpc.protoPath');
if(protoPath) transformedJson.request.protoPath = protoPath;
if (protoPath) transformedJson.request.protoPath = protoPath;
transformedJson.request.auth.mode = _.get(json, 'grpc.auth', 'none');
transformedJson.request.body = _.get(json, 'body', {
mode: 'grpc',

View File

@@ -9,7 +9,7 @@ const chalk = require('chalk');
const createCollectionJsonFromPathname = (collectionPath) => {
const environmentsPath = path.join(collectionPath, `environments`);
// get the collection bruno json config [<collection-path>/bruno.json]
const brunoConfig = getCollectionBrunoJsonConfig(collectionPath);
@@ -29,17 +29,16 @@ const createCollectionJsonFromPathname = (collectionPath) => {
if (stats.isDirectory()) {
if (filePath === environmentsPath) continue;
if (filePath.startsWith('.git') || filePath.startsWith('node_modules')) continue;
// get the folder root
let folderItem = { name: file, pathname: filePath, type: 'folder', items: traverse(filePath) }
let folderItem = { name: file, pathname: filePath, type: 'folder', items: traverse(filePath) };
const folderBruJson = getFolderRoot(filePath);
if (folderBruJson) {
folderItem.root = folderBruJson;
folderItem.seq = folderBruJson.meta.seq;
}
currentDirItems.push(folderItem);
}
else {
} else {
if (['collection.bru', 'folder.bru'].includes(file)) continue;
if (path.extname(filePath) !== '.bru') continue;
@@ -78,7 +77,7 @@ const createCollectionJsonFromPathname = (collectionPath) => {
root: collectionRoot,
pathname: collectionPath,
items: collectionItems
}
};
return collection;
};
@@ -96,7 +95,7 @@ const getCollectionBrunoJsonConfig = (dir) => {
const brunoConfigFile = fs.readFileSync(brunoJsonPath, 'utf8');
const brunoConfig = JSON.parse(brunoConfigFile);
return brunoConfig;
}
};
const getCollectionRoot = (dir) => {
const collectionRootPath = path.join(dir, 'collection.bru');
@@ -191,7 +190,7 @@ const mergeVars = (collection, request, requestTreePath) => {
request.folderVariables = folderVariables;
request.requestVariables = requestVariables;
if(request?.vars) {
if (request?.vars) {
request.vars.req = Array.from(reqVars, ([name, value]) => ({
name,
value,
@@ -309,7 +308,7 @@ const mergeAuth = (collection, request, requestTreePath) => {
if (request.auth && request.auth.mode === 'inherit') {
request.auth = effectiveAuth;
}
}
};
const getAllRequestsInFolder = (folderItems = [], recursive = true) => {
let requests = [];
@@ -330,12 +329,11 @@ const getAllRequestsInFolder = (folderItems = [], recursive = true) => {
const getAllRequestsAtFolderRoot = (folderItems = []) => {
return getAllRequestsInFolder(folderItems, false);
}
};
const getCallStack = (resolvedPaths = [], collection, {recursive}) => {
const getCallStack = (resolvedPaths = [], collection, { recursive }) => {
let requestItems = [];
if (!resolvedPaths || !resolvedPaths.length) {
return requestItems;
}
@@ -380,7 +378,7 @@ const safeWriteFileSync = (filePath, content) => {
/**
* Creates a Bruno collection directory structure from a Bruno collection object
*
*
* @param {Object} collection - The Bruno collection object
* @param {string} dirPath - The output directory path
*/
@@ -392,9 +390,9 @@ const createCollectionFromBrunoObject = async (collection, dirPath) => {
type: 'collection',
ignore: ['node_modules', '.git']
};
fs.writeFileSync(
path.join(dirPath, 'bruno.json'),
path.join(dirPath, 'bruno.json'),
JSON.stringify(brunoConfig, null, 2)
);
@@ -424,7 +422,7 @@ const createCollectionFromBrunoObject = async (collection, dirPath) => {
/**
* Recursively processes collection items to create files and folders
*
*
* @param {Array} items - Collection items
* @param {string} currentPath - Current directory path
*/
@@ -487,17 +485,17 @@ const processCollectionItems = async (items = [], currentPath) => {
}
};
const sortByNameThenSequence = items => {
const isSeqValid = seq => Number.isFinite(seq) && Number.isInteger(seq) && seq > 0;
const sortByNameThenSequence = (items) => {
const isSeqValid = (seq) => Number.isFinite(seq) && Number.isInteger(seq) && seq > 0;
// Sort folders alphabetically by name
const alphabeticallySorted = [...items].sort((a, b) => a.name && b.name && a.name.localeCompare(b.name));
// Extract folders without 'seq'
const withoutSeq = alphabeticallySorted.filter(f => !isSeqValid(f['seq']));
const withoutSeq = alphabeticallySorted.filter((f) => !isSeqValid(f['seq']));
// Extract folders with 'seq' and sort them by 'seq'
const withSeq = alphabeticallySorted.filter(f => isSeqValid(f['seq'])).sort((a, b) => a.seq - b.seq);
const withSeq = alphabeticallySorted.filter((f) => isSeqValid(f['seq'])).sort((a, b) => a.seq - b.seq);
const sortedItems = withoutSeq;
@@ -516,7 +514,7 @@ const sortByNameThenSequence = items => {
const newGroup = Array.isArray(existingItem)
? [...existingItem, item]
: [existingItem, item];
withoutSeq.splice(position, 1, newGroup);
} else {
// Insert item at the specified position
@@ -528,7 +526,6 @@ const sortByNameThenSequence = items => {
return sortedItems.flat();
};
module.exports = {
createCollectionJsonFromPathname,
mergeHeaders,
@@ -541,4 +538,4 @@ module.exports = {
getAllRequestsInFolder,
getAllRequestsAtFolderRoot,
getCallStack
}
};

View File

@@ -120,41 +120,41 @@ const getSubDirectories = (dir) => {
/**
* Sanitizes a filename to make it safe for filesystem operations
*
*
* @param {string} name - The name to sanitize
* @returns {string} - The sanitized name
*/
const sanitizeName = (name) => {
if (!name) return '';
const invalidCharacters = /[<>:"/\\|?*\x00-\x1F]/g;
return name
.replace(invalidCharacters, '-') // replace invalid characters with hyphens
.replace(/^[.\s-]+/, '') // remove leading dots, hyphens and spaces
.replace(/[.\s]+$/, ''); // remove trailing dots and spaces (keep trailing hyphens)
.replace(invalidCharacters, '-') // replace invalid characters with hyphens
.replace(/^[.\s-]+/, '') // remove leading dots, hyphens and spaces
.replace(/[.\s]+$/, ''); // remove trailing dots and spaces (keep trailing hyphens)
};
/**
* Validates if a name is valid for the filesystem
*
*
* @param {string} name - The name to validate
* @returns {boolean} - True if the name is valid, false otherwise
*/
const validateName = (name) => {
if (!name) return false;
const reservedDeviceNames = /^(CON|PRN|AUX|NUL|COM[0-9]|LPT[0-9])$/i;
const firstCharacter = /^[^.\s\-\<>:"/\\|?*\x00-\x1F]/; // no dot, space, or hyphen at start
const middleCharacters = /^[^<>:"/\\|?*\x00-\x1F]*$/; // no invalid characters
const lastCharacter = /[^.\s]$/; // no dot or space at end, hyphen allowed
if (name.length > 255) return false; // max name length
const middleCharacters = /^[^<>:"/\\|?*\x00-\x1F]*$/; // no invalid characters
const lastCharacter = /[^.\s]$/; // no dot or space at end, hyphen allowed
if (name.length > 255) return false; // max name length
if (reservedDeviceNames.test(name)) return false; // windows reserved names
return (
firstCharacter.test(name) &&
middleCharacters.test(name) &&
lastCharacter.test(name)
firstCharacter.test(name)
&& middleCharacters.test(name)
&& lastCharacter.test(name)
);
};

View File

@@ -39,4 +39,4 @@ const createFormData = (data, collectionPath) => {
module.exports = {
createFormData
}
};

View File

@@ -79,15 +79,14 @@ class PatchedHttpsProxyAgent extends HttpsProxyAgent {
}
}
const getSystemProxyEnvVariables = () => {
const { http_proxy, HTTP_PROXY, https_proxy, HTTPS_PROXY, no_proxy, NO_PROXY } = process.env;
return {
http_proxy: http_proxy || HTTP_PROXY,
https_proxy: https_proxy || HTTPS_PROXY,
no_proxy: no_proxy || NO_PROXY
};
}
};
};
module.exports = {
shouldUseProxy,

View File

@@ -1,28 +1,27 @@
// Check for meaningful test() calls (not commented out or in strings)
const hasExecutableTestInScript = (script) => {
if (!script) return false;
// Remove single-line comments (// ...) and multi-line comments (/* ... */)
let cleanScript = script
.replace(/\/\/.*$/gm, '') // Remove line comments
.replace(/\/\/.*$/gm, '') // Remove line comments
.replace(/\/\*[\s\S]*?\*\//g, ''); // Remove block comments
// Remove string literals to avoid matching test() inside strings
cleanScript = cleanScript
.replace(/"(?:[^"\\]|\\.)*"/g, '""') // Remove double-quoted strings
.replace(/'(?:[^'\\]|\\.)*'/g, "''") // Remove single-quoted strings
.replace(/"(?:[^"\\]|\\.)*"/g, '""') // Remove double-quoted strings
.replace(/'(?:[^'\\]|\\.)*'/g, '\'\'') // Remove single-quoted strings
.replace(/`(?:[^`\\]|\\.)*`/g, '``'); // Remove template literals
// Look for standalone test() calls (not object method calls like obj.test())
// Find all test( occurrences and check they're not preceded by dots
let hasValidTest = false;
let searchFrom = 0;
while (true) {
const index = cleanScript.indexOf('test', searchFrom);
if (index === -1) break;
// Check if this looks like test( with optional whitespace
const afterTest = cleanScript.substring(index + 4);
if (/^\s*\(/.test(afterTest)) {
@@ -32,13 +31,13 @@ const hasExecutableTestInScript = (script) => {
break;
}
}
searchFrom = index + 1;
}
return hasValidTest;
};
module.exports = {
hasExecutableTestInScript
};
};