Gathering detailed insights and metrics for git-validate-tyrchen
Gathering detailed insights and metrics for git-validate-tyrchen
Gathering detailed insights and metrics for git-validate-tyrchen
Gathering detailed insights and metrics for git-validate-tyrchen
npm install git-validate-tyrchen
Typescript
Module System
Node Version
NPM Version
JavaScript (77.71%)
Shell (22.29%)
Total Downloads
0
Last Day
0
Last Week
0
Last Month
0
Last Year
0
MIT License
153 Commits
2 Watchers
2 Branches
1 Contributors
Updated on Oct 06, 2015
Latest Version
2.2.0
Package Id
git-validate-tyrchen@2.2.0
Size
9.56 kB
NPM Version
2.14.2
Node Version
4.0.0
Cumulative downloads
Total Downloads
Last Day
0%
NaN
Compared to previous day
Last Week
0%
NaN
Compared to previous week
Last Month
0%
NaN
Compared to previous month
Last Year
0%
NaN
Compared to previous year
#git-validate
This is a super simple framework to facilitate creating your own modules similar to precommit-hook.
This module isn't intended to be used directly in your projects (thought it can be), but rather as the dependency of a module that you create that will act as a template of sorts.
To create a validate module, first make a new directory and use npm init
to initialize your module:
1mkdir validate-nlf 2cd validate-nlf 3npm init
Follow the prompts, and when complete install this module:
1npm install --save git-validate
Now, let's say we want to provide a default .jshintrc
file, let's go ahead and create that file in our new directory and fill it with some options:
1vim jshintrc
1{ 2 "node": true, 3 4 "curly": true, 5 "latedef": true, 6 "quotmark": true, 7 "undef": true, 8 "unused": true, 9 "trailing": true 10}
Note that we saved the file as jshintrc
without the leading dot.
Next, let's create our install script:
1vim install.js
1var Validate = require('git-validate'); 2 3Validate.copy('jshintrc', '.jshintrc');
This instructs git-validate to copy the jshintrc
file in our module to .jshintrc
in the root of the project that installs it.
Now we edit our package.json
to tell it about our install script:
1 "scripts": { 2 "install": "node install.js" 3 }
And that's it for the simplest possible example. Now anytime you install validate-nlf
you'll automatically get a .jshintrc
file in your project.
This wouldn't be any fun without the git hooks though, so let's extend it a bit further to make sure that jshint
is run any time a user tries to git commit
after installing our module. We can do that by configuring the hook in our install script like so:
1Validate.installScript('lint', 'jshint .'); 2Validate.configureHook('pre-commit', ['lint']);
Great, that's it!
Now when a user installs your package the installScript
method will see if they already have a script in their package.json named lint
, if they do not it will add one that runs "jshint ."
. The second line will also check their package.json for a pre-commit
key, which is used to configure that specific git hook. If the key does not exist, it will be added with the value ["lint"]
telling git-validate to run the "lint" script on pre-commit
.
git-validate exports a few methods to be used for creating your custom hooks.
copy
Copy a file or directory from your hook to a target project.
1Validate.copy(source, target, options);
Where source
is a path relative to your install script, and target
is a path relative to the root of the project that is installing the module. For example if my module has the layout:
bin/install
jshintrc
And I wish for the file jshintrc
to be placed in the root of projects as .jshintrc
when running bin/install
, I would call Validate.copy('../jshintrc', '.jshintrc')
.
Note that source
may be a file or a directory. If a directory is specified than a new directory will be created at target
and the full contents of source will be copied to the target
directory recursively.
The only option
currently available is overwrite
. When set to true
overwrite will always copy the given file, overwriting any existing destination file. If this is not set, copy
will instead silently fail and leave the old file in place.
installHooks
Install one or more git hooks to the current repo.
1Validate.installHooks('pre-commit'); 2Validate.installHooks(['pre-commit', 'pre-push']);
This method will copy the hook script to the appropriate path in your repo's .git/hooks
path.
configureHook
Provide a default configuration for a given hook.
1Validate.configureHook('pre-commit', ['lint', 'test']);
would write
1{ 2 "pre-commit": ["lint", "test"] 3}
to your package.json, but only if the "pre-commit"
key was not already set.
installScript
Configure a script (if it is not already configured) for the project via package.json.
1Validate.installScript('test', 'lab -a code');
would write
1{ 2 "scripts": { 3 "test": "lab -a code" 4 } 5}
to your package.json. If the "test"
script was already defined, this method will do nothing.
In addition to the scripts
property, your package.json file will be parsed and checked for keys matching the name of your git hooks (e.g. pre-commit
, pre-push
, etc) and used to provide a list of hooks to be run for each hook. The keys must be an array of script names to be run. If any of the scripts are not defined, they will be skipped and a message will be printed showing that no script was found.
It is possible to run scripts only for a specific branch by specifying the key in your package.json
as hook-name#branch
:
1{ 2 "pre-commit": ["lint", "test"], 3 "pre-commit#dev": ["lint"] 4}
In the above example, when run in the dev
branch only the lint
script will be run, however in all other branches both lint
and test
will be run.
No vulnerabilities found.
Reason
no binaries found in the repo
Reason
0 existing vulnerabilities detected
Reason
license file detected
Details
Reason
0 commit(s) and 0 issue activity found in the last 90 days -- score normalized to 0
Reason
Found 0/30 approved changesets -- score normalized to 0
Reason
no SAST tool detected
Details
Reason
no effort to earn an OpenSSF best practices badge detected
Reason
project is not fuzzed
Details
Reason
branch protection not enabled on development/release branches
Details
Reason
security policy file not detected
Details
Score
Last Scanned on 2025-07-07
The Open Source Security Foundation is a cross-industry collaboration to improve the security of open source software (OSS). The Scorecard provides security health metrics for open source projects.
Learn More