Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Website #125

Merged
merged 8 commits into from Jul 28, 2019
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.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
1 change: 1 addition & 0 deletions .eslintignore
@@ -0,0 +1 @@
website
119 changes: 63 additions & 56 deletions .gitignore
@@ -1,81 +1,88 @@
####################################
####################################
### OS Files
####################################
####################################
Thumbs.db
.DS_Store
# Logs
logs
*.log
npm-debug.log*
yarn-debug.log*
yarn-error.log*
lerna-debug.log*

# Diagnostic reports (https://nodejs.org/api/report.html)
report.[0-9]*.[0-9]*.[0-9]*.[0-9]*.json

# Runtime data
pids
*.pid
*.seed
*.pid.lock

# Directory for instrumented libs generated by jscoverage/JSCover
lib-cov

####################################
####################################
### Git
####################################
####################################
*.orig
# Coverage directory used by tools like istanbul
coverage
*.lcov

# nyc test coverage
.nyc_output

# Grunt intermediate storage (https://gruntjs.com/creating-plugins#storing-task-files)
.grunt

# Bower dependency directory (https://bower.io/)
bower_components

####################################
####################################
### Sublime Text
####################################
####################################
# cache files for sublime text
*.tmlanguage.cache
*.tmPreferences.cache
*.stTheme.cache
# node-waf configuration
.lock-wscript

# workspace files are user-specific
*.sublime-workspace
# Compiled binary addons (https://nodejs.org/api/addons.html)
build/Release

# sublime project files
*.sublime-project
# Dependency directories
node_modules/
jspm_packages/

# sftp configuration file
sftp-config.json
# TypeScript v1 declaration files
typings/

# TypeScript cache
*.tsbuildinfo

# Optional npm cache directory
.npm

# Optional eslint cache
.eslintcache

####################################
####################################
### Node
####################################
####################################
# Logs
logs
*.log

# Coverage directory used by tools like istanbul
coverage
# Optional REPL history
.node_repl_history

# Compiled binary addons (http://nodejs.org/api/addons.html)
build/Release
# Output of 'npm pack'
*.tgz

# Dependency directory
node_modules
# Yarn Integrity file
.yarn-integrity

# dotenv environment variables file
.env
.env.test

# parcel-bundler cache (https://parceljs.org/)
.cache

# next.js build output
.next

####################################
####################################
### Mocha
####################################
####################################
mocha.json
# nuxt.js build output
.nuxt

# vuepress build output
.vuepress/dist

# Serverless directories
.serverless/

# FuseBox cache
.fusebox/

####################################
####################################
### nyc
####################################
####################################
.nyc_output/
coverage/
# DynamoDB Local files
.dynamodb/
184 changes: 184 additions & 0 deletions docs/api.md
@@ -0,0 +1,184 @@
---
id: api
title: Node.js API
---

npm-package-json-lint exports two main objects: `CLIEngine` and `NpmPackageJsonLint`.

## NpmPackageJsonLint()

Creates an instance of NpmPackageJsonLint

`NpmPackageJsonLint` has one public method, `lint`. `lint` takes a package.json object in object form and a config object as parameters.

### .lint(packageJsonData, configObj)

Runs configured rules against the provided package.json object.

#### packageJsonData

Type: `Object`

A package.json file in object form.

#### configObj

Type: `Object`

A valid configuration object.

#### Example

The following example demostrates how to use `lint`.

```js
const {NpmPackageJsonLint} = require('npm-package-json-lint');

const npmPackageJsonLint = new NpmPackageJsonLint();
const results = npmPackageJsonLint.lint(packageJsonDataAsObject, configObject);
```

#### Return

`lint` returns an object with an array of `LintIssue`s. Please see `LintIssue` section for more detail.

```js
{
issues: [
{
lintId: 'require-name',
severity: 'error',
node: 'name',
lintMessage: 'name is required'
}
]
}
```

### .version

Calling `.version` on an instance of `NpmPackageJsonLint` will return the version number of npm-package-json-lint that the linter is associated with.

#### Example

```js
const {NpmPackageJsonLint} = require('npm-package-json-lint');

const npmPackageJsonLint = new NpmPackageJsonLint();

npmPackageJsonLint.version;
// => '3.0.0'
```

## CLIEngine(options)

Creates an instance of CLIEngine

### options

Type: `Object`

CLIEngine configuration object

* `configFile` {String} Name of module/file to use.
* `cwd` {String} The current working diretory for all file operations.
* `useConfigFiles` {Boolean} False disables use of .npmpackagejsonlintrc.json files and npmpackagejsonlint.config.js files.
* `rules` {Object} An object of rules to use.

### Example

The following example demostrates how to initialize a `CLIEngine`.

```js
const {CLIEngine} = require('npm-package-json-lint');

const cliEngineOptions = {
configFile: '',
cwd: process.cwd(),
useConfigFiles: true,
rules: {}
};

const cliEngine = new CLIEngine(cliEngineOptions);
```

### .executeOnPackageJsonFiles(patterns)

Runs npm-package-json-lint against the array a patterns.

#### patterns

Type: `Array`

An array of glob patterns

#### Example

The following example demostrates how to use `executeOnPackageJsonFiles`.

```js
const {CLIEngine} = require('npm-package-json-lint');

const cliEngineOptions = {
configFile: '',
cwd: process.cwd(),
useConfigFiles: true,
rules: {}
};
const patterns = ['.'];

const cliEngine = new CLIEngine(cliEngineOptions);
const results = cliEngine.executeOnPackageJsonFiles(patterns);
```

#### Return

`executeOnPackageJsonFiles` returns an object with an array of results.

```js
{
results: [
{
filePath: './package.json',
issues: [
{
lintId: 'require-name',
severity: 'error',
node: 'name',
lintMessage: 'name is required'
}
],
errorCount: 1,
warningCount: 0
}
],
errorCount: 1,
warningCount: 0
}
```

### .version

Calling `.version` on an instance of `CLIEngine` will return the version number of npm-package-json-lint that the CLIEngine is associated with.

#### Example

```js
const {CLIEngine} = require('npm-package-json-lint');

const cliEngineOptions = {
configFile: '',
cwd: process.cwd(),
useConfigFiles: true,
rules: {}
};

const cliEngine = new CLIEngine(cliEngineOptions);

cliEngine.version;
// => '3.0.0'
```

> **WARNING**

Only the functions documented above are supported. All other functions that are exposed may change with any release. Please refrain from using them.