Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,11 @@ jobs:
strategy:
matrix:
# Have to use 18.x and up because later versions of eslint require structuredClone
node-version: [18.x, 20.x, 22.x]
node-version: [18.x, 20.x, 22.x, 24.x]
steps:
- uses: actions/checkout@v4
- uses: actions/checkout@v6
- name: Run tests against node ${{ matrix.node-version }}
uses: actions/setup-node@v3
uses: actions/setup-node@v6
with:
node-version: ${{ matrix.node-version }}
cache: "npm"
Expand Down
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
/node_modules/
*.log
.vs/
.DS_Store
.DS_Store
tools/
6 changes: 5 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,10 +1,14 @@
# CHANGELOG

## 2.2.2

- Added support for ESLint 10

## 2.2.1

### Minor

- Add support for the official ESLint json parser
- Added support for the official ESLint json parser

## 2.1.0

Expand Down
7 changes: 3 additions & 4 deletions dist/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ function shouldIgnore(value, toIgnore) {
}
const meta = {
name: "eslint-plugin-no-secrets",
version: "2.1.1",
version: "2.2.2",
};
exports.meta = meta;
const noSecrets = {
Expand All @@ -42,13 +42,12 @@ const noSecrets = {
},
docs: {
description: "An eslint rule that looks for possible leftover secrets in code",
category: "Best Practices",
},
},
create(context) {
var _a;
const { tolerance, additionalRegexes, ignoreContent, ignoreModules, ignoreIdentifiers, additionalDelimiters, ignoreCase, } = (0, utils_1.checkOptions)(context.options[0] || {});
const sourceCode = context.getSourceCode() || context.sourceCode;
const sourceCode = (0, utils_1.getSourceCode)(context);
const allPatterns = Object.assign({}, regexes_1.default, additionalRegexes);
const allDelimiters = additionalDelimiters.concat([" "]);
function splitIntoTokens(value) {
Expand Down Expand Up @@ -110,7 +109,7 @@ const noSecrets = {
comments.forEach((comment) => checkString(comment.value, comment));
return {
/**
* For the official json
* For the official eslint json plugin
*/
String(node) {
const { value } = node;
Expand Down
12 changes: 2 additions & 10 deletions dist/no-pattern-match.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,14 +11,8 @@ function globalizeRegularExpression(regexp) {
return regexp;
return new RegExp(regexp, regexp.flags + "g");
}
function globalizeAllRegularExps(patterns) {
return Object.fromEntries(Object.entries(patterns).map(([name, pattern]) => [
name,
globalizeRegularExpression(pattern),
]));
}
function parseAndValidateOptions({ patterns }) {
const compiledRegexes = (0, utils_1.validateRecordOfRegex)((0, utils_1.plainObjectOption)(patterns, "patterns", utils_1.DEFAULT_ADDTIONAL_REGEXES));
const compiledRegexes = (0, utils_1.validateRecordOfRegex)((0, utils_1.plainObjectOption)(patterns, "patterns", utils_1.DEFAULT_ADDITIONAL_REGEXES));
return {
patterns: compiledRegexes,
};
Expand Down Expand Up @@ -118,13 +112,11 @@ const noPatternMatch = {
},
docs: {
description: "An eslint rule that does pattern matching against an entire file",
category: "Best Practices",
},
},
create(context) {
var _a;
const { patterns } = parseAndValidateOptions(context.options[0] || {});
const sourceCode = ((_a = context === null || context === void 0 ? void 0 : context.getSourceCode) === null || _a === void 0 ? void 0 : _a.call(context)) || context.sourceCode;
const sourceCode = (0, utils_1.getSourceCode)(context);
const patternList = Object.entries(patterns);
const text = sourceCode.text;
const newLinePos = findAllNewLines(text);
Expand Down
27 changes: 21 additions & 6 deletions dist/utils.js
Original file line number Diff line number Diff line change
@@ -1,21 +1,22 @@
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.FULL_TEXT_MATCH = exports.PATTERN_MATCH = exports.HIGH_ENTROPY = exports.DEFAULT_ADDTIONAL_REGEXES = void 0;
exports.FULL_TEXT_MATCH = exports.PATTERN_MATCH = exports.HIGH_ENTROPY = exports.DEFAULT_ADDITIONAL_REGEXES = void 0;
exports.isPlainObject = isPlainObject;
exports.plainObjectOption = plainObjectOption;
exports.validateRecordOfRegex = validateRecordOfRegex;
exports.checkOptions = checkOptions;
exports.shannonEntropy = shannonEntropy;
exports.isModulePathString = isModulePathString;
exports.getIdentifierName = getIdentifierName;
exports.getSourceCode = getSourceCode;
const MATH_LOG_2 = Math.log(2);
/**
* Charset especially designed to ignore common regular expressions (eg [] and {}), imports/requires (/.), and css classes (-), and other special characters,
* which raise a lot of false postives and aren't usually in passwords/secrets
*/
const CHARSET = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+=!|*^@~`$%+?\"'_<>".split("");
const DEFAULT_TOLERANCE = 4;
exports.DEFAULT_ADDTIONAL_REGEXES = {};
exports.DEFAULT_ADDITIONAL_REGEXES = {};
function isPlainObject(obj) {
return typeof obj === "object" && obj.constructor === Object;
}
Expand All @@ -36,15 +37,17 @@ function compileListOfPatterns(patterns = [], name) {
pattern instanceof RegExp ? pattern : new RegExp(String(pattern));
}
catch (e) {
throw new Error("Failed to compiled the regexp " + patterns[i]);
throw new Error(`Failed to compiled the regexp ${patterns[i]}`);
}
}
return compiledPatterns;
}
function booleanOption(value, name, defaultValue) {
//TODO: This is kind of ridiclous check, fix this
value = value || defaultValue;
if (typeof value !== "boolean") {
if (typeof value === "undefined") {
return defaultValue;
}
throw new Error(`The option '${name}' must be boolean`);
}
return value;
Expand Down Expand Up @@ -83,7 +86,7 @@ function checkOptions({ tolerance, additionalRegexes, ignoreContent, ignoreModul
if (typeof tolerance !== "number" || tolerance <= 0) {
throw new Error("The option tolerance must be a positive (eg greater than zero) number");
}
additionalRegexes = plainObjectOption(additionalRegexes, "additionalRegexes", exports.DEFAULT_ADDTIONAL_REGEXES);
additionalRegexes = plainObjectOption(additionalRegexes, "additionalRegexes", exports.DEFAULT_ADDITIONAL_REGEXES);
const compiledRegexes = validateRecordOfRegex(additionalRegexes);
return {
tolerance,
Expand Down Expand Up @@ -116,7 +119,6 @@ const MODULE_FUNCTIONS = ["import", "require"];
/**
* Used to detect "import()" and "require()"
* Inspired by https://github.com/benmosher/eslint-plugin-import/blob/45bfe472f38ef790c11efe45ffc59808c67a3f94/src/core/staticRequire.js
* @param {*} node
*/
function isStaticImportOrRequire(node) {
return (node &&
Expand Down Expand Up @@ -165,3 +167,16 @@ function getAssignmentName(node) {
exports.HIGH_ENTROPY = "HIGH_ENTROPY";
exports.PATTERN_MATCH = "PATTERN_MATCH";
exports.FULL_TEXT_MATCH = "FULL_TEXT_MATCH";
/**
* Backwards and forward getSourceCode function
* @param context
* @returns
*/
function getSourceCode(context) {
if (context === null || context === void 0 ? void 0 : context.sourceCode) {
return context.sourceCode;
}
else {
return context.getSourceCode();
}
}
Loading