eslint-plugin-diff
Advanced tools
Comparing version 1.0.6 to 1.0.7
import { Range } from "./Range"; | ||
declare const getDiffForFile: (filePath: string, staged?: boolean) => string; | ||
declare const getDiffFileList: (staged?: boolean) => string[]; | ||
declare const getIgnorePatterns: (staged?: boolean) => string[]; | ||
declare const getRangesForDiff: (diff: string) => Range[]; | ||
export { getDiffForFile, getRangesForDiff, getDiffFileList }; | ||
export { getDiffForFile, getIgnorePatterns, getRangesForDiff, getDiffFileList }; | ||
export type { Range }; |
@@ -22,3 +22,3 @@ "use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.getDiffFileList = exports.getRangesForDiff = exports.getDiffForFile = void 0; | ||
exports.getDiffFileList = exports.getRangesForDiff = exports.getIgnorePatterns = exports.getDiffForFile = void 0; | ||
const child_process = __importStar(require("child_process")); | ||
@@ -42,3 +42,3 @@ const path = __importStar(require("path")); | ||
"--unified=0", | ||
(_a = JSON.stringify(process.env.ESLINT_PLUGIN_DIFF_COMMIT)) !== null && _a !== void 0 ? _a : "HEAD", | ||
JSON.stringify((_a = process.env.ESLINT_PLUGIN_DIFF_COMMIT) !== null && _a !== void 0 ? _a : "HEAD"), | ||
"--", | ||
@@ -66,3 +66,3 @@ sanitizeFilePath(filePath), | ||
staged && "--staged", | ||
(_a = JSON.stringify(process.env.ESLINT_PLUGIN_DIFF_COMMIT)) !== null && _a !== void 0 ? _a : "HEAD", | ||
JSON.stringify((_a = process.env.ESLINT_PLUGIN_DIFF_COMMIT) !== null && _a !== void 0 ? _a : "HEAD"), | ||
] | ||
@@ -81,2 +81,23 @@ .filter(Boolean) | ||
exports.getDiffFileList = getDiffFileList; | ||
let gitFileListCache; | ||
const getGitFileList = () => { | ||
if (gitFileListCache === undefined) { | ||
const command = ["git", "ls-files"].filter(Boolean).join(" "); | ||
gitFileListCache = child_process | ||
.execSync(command) | ||
.toString() | ||
.trim() | ||
.split("\n") | ||
.map((filePath) => path.resolve(filePath)); | ||
} | ||
return gitFileListCache; | ||
}; | ||
const getIgnorePatterns = (staged = false) => { | ||
const changedFiles = getDiffFileList(staged); | ||
const unchangedFiles = getGitFileList() | ||
.filter((x) => !changedFiles.includes(x)) | ||
.map((x) => path.join("/", path.relative(process.cwd(), x))); | ||
return unchangedFiles; | ||
}; | ||
exports.getIgnorePatterns = getIgnorePatterns; | ||
const isHunkHeader = (input) => { | ||
@@ -109,9 +130,7 @@ const hunkHeaderRE = new RegExp(/^@@ .* @@/g); | ||
const removeNullRanges = (r) => r !== null; | ||
const getRangesForDiff = (diff) => { | ||
return diff | ||
.split("\n") | ||
.filter(isHunkHeader) | ||
.map(getRangeForChangedLines) | ||
.filter(removeNullRanges); | ||
}; | ||
const getRangesForDiff = (diff) => diff | ||
.split("\n") | ||
.filter(isHunkHeader) | ||
.map(getRangeForChangedLines) | ||
.filter(removeNullRanges); | ||
exports.getRangesForDiff = getRangesForDiff; |
@@ -1,1 +0,29 @@ | ||
export {}; | ||
declare const configs: { | ||
diff: { | ||
plugins: string[]; | ||
overrides: { | ||
files: string[]; | ||
processor: string; | ||
}[]; | ||
ignorePatterns: string[]; | ||
}; | ||
staged: { | ||
plugins: string[]; | ||
overrides: { | ||
files: string[]; | ||
processor: string; | ||
}[]; | ||
ignorePatterns: string[]; | ||
}; | ||
}; | ||
declare const processors: { | ||
diff: { | ||
postprocess: (messages: import("eslint").Linter.LintMessage[][], filename: string) => import("eslint").Linter.LintMessage[]; | ||
supportsAutofix: boolean; | ||
}; | ||
staged: { | ||
postprocess: (messages: import("eslint").Linter.LintMessage[][], filename: string) => import("eslint").Linter.LintMessage[]; | ||
supportsAutofix: boolean; | ||
}; | ||
}; | ||
export { configs, processors }; |
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.processors = exports.configs = void 0; | ||
const processors_1 = require("./processors"); | ||
module.exports = { | ||
configs: { diff: processors_1.diffConfig, staged: processors_1.stagedConfig }, | ||
processors: { diff: processors_1.diff, staged: processors_1.staged }, | ||
}; | ||
const configs = { diff: processors_1.diffConfig, staged: processors_1.stagedConfig }; | ||
exports.configs = configs; | ||
const processors = { diff: processors_1.diff, staged: processors_1.staged }; | ||
exports.processors = processors; | ||
module.exports = { configs, processors }; |
import type { Linter } from "eslint"; | ||
declare const diff: { | ||
preprocess: (text: string, filename: string) => { | ||
text: string; | ||
filename: string; | ||
}[]; | ||
postprocess: (messages: Linter.LintMessage[][], filename: string) => Linter.LintMessage[]; | ||
@@ -16,8 +12,5 @@ supportsAutofix: boolean; | ||
}[]; | ||
ignorePatterns: string[]; | ||
}; | ||
declare const staged: { | ||
preprocess: (text: string, filename: string) => { | ||
text: string; | ||
filename: string; | ||
}[]; | ||
postprocess: (messages: Linter.LintMessage[][], filename: string) => Linter.LintMessage[]; | ||
@@ -32,3 +25,4 @@ supportsAutofix: boolean; | ||
}[]; | ||
ignorePatterns: string[]; | ||
}; | ||
export { diff, diffConfig, staged, stagedConfig }; |
@@ -8,6 +8,13 @@ "use strict"; | ||
const diff = { | ||
preprocess: (text, filename) => git_1.getDiffFileList().includes(filename) ? [{ text, filename }] : [], | ||
postprocess: (messages, filename) => messages | ||
.map((message) => message.filter(({ line }) => git_1.getRangesForDiff(git_1.getDiffForFile(filename)).some(isLineWithinRange(line)))) | ||
.reduce((a, b) => a.concat(b), []), | ||
postprocess: (messages, filename) => { | ||
const shouldKeepFile = git_1.getDiffFileList().includes(filename); | ||
return shouldKeepFile | ||
? messages | ||
.map((message) => message.filter(({ fatal, line }) => { | ||
const shouldKeepLine = git_1.getRangesForDiff(git_1.getDiffForFile(filename)).some(isLineWithinRange(line)); | ||
return fatal !== null && fatal !== void 0 ? fatal : shouldKeepLine; | ||
})) | ||
.reduce((a, b) => a.concat(b), []) | ||
: []; | ||
}, | ||
supportsAutofix: true, | ||
@@ -24,9 +31,17 @@ }; | ||
], | ||
ignorePatterns: git_1.getIgnorePatterns(), | ||
}; | ||
exports.diffConfig = diffConfig; | ||
const staged = { | ||
preprocess: (text, filename) => git_1.getDiffFileList(STAGED).includes(filename) ? [{ text, filename }] : [], | ||
postprocess: (messages, filename) => messages | ||
.map((message) => message.filter(({ line }) => git_1.getRangesForDiff(git_1.getDiffForFile(filename, STAGED)).some(isLineWithinRange(line)))) | ||
.reduce((a, b) => a.concat(b), []), | ||
postprocess: (messages, filename) => { | ||
const shouldKeepFile = git_1.getDiffFileList().includes(filename); | ||
return shouldKeepFile | ||
? messages | ||
.map((message) => message.filter(({ fatal, line }) => { | ||
const shouldKeepLine = git_1.getRangesForDiff(git_1.getDiffForFile(filename, STAGED)).some(isLineWithinRange(line)); | ||
return fatal !== null && fatal !== void 0 ? fatal : shouldKeepLine; | ||
})) | ||
.reduce((a, b) => a.concat(b), []) | ||
: []; | ||
}, | ||
supportsAutofix: true, | ||
@@ -43,3 +58,4 @@ }; | ||
], | ||
ignorePatterns: git_1.getIgnorePatterns(STAGED), | ||
}; | ||
exports.stagedConfig = stagedConfig; |
{ | ||
"name": "eslint-plugin-diff", | ||
"version": "1.0.6", | ||
"version": "1.0.7", | ||
"description": "Run ESLint on your changes only", | ||
@@ -31,3 +31,3 @@ "keywords": [ | ||
"release": "np", | ||
"test": "jest", | ||
"test": "jest --coverage", | ||
"typecheck": "tsc --project tsconfig.json", | ||
@@ -34,0 +34,0 @@ "prepublish": "yarn run clean && yarn run build", |
# eslint-plugin-diff | ||
Run ESLint on your changes only | ||
Run ESLint on your changed lines only. Now with CI support! | ||
@@ -5,0 +5,0 @@ ## What problem does it solve? |
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
14843
283