GithubHelp home page GithubHelp logo

isabella232 / electron-docs-linter Goto Github PK

View Code? Open in Web Editor NEW

This project forked from electron/electron-docs-linter

0.0 0.0 0.0 1.56 MB

Parse and validate Electron's API documentation

Home Page: http://npm.im/electron-docs-linter

JavaScript 100.00%

electron-docs-linter's Introduction

electron-docs-linter Build Status

Parse and validate Electron's API documentation.

Installation

npm install electron-docs-linter --save

CLI Usage

To lint the docs:

electron-docs-linter path/to/electron/docs

If errors are found, they are printed to STDERR and the process exits un-gracefully.

To lint the docs and save the generated JSON schema to a file:

electron-docs-linter docs/api --version=1.2.3 --outfile=api.json

Programmatic Usage

The module exports a function that parses markdown docs in a given directory, then returns a JSON representation of all the APIs.

const lint = require('electron-docs-linter')
const docPath = './test/fixtures/electron/docs/api'
const targetVersion = '1.2.3' // the soon-to-be-released version of electron

lint(docPath, targetVersion).then(function (apis) {
  // `apis` is an array of API objects. To find one:
  var win = apis.find(api => api.name === 'BrowserWindow')

  // The array also has a string key for each API name, so
  // you can access APIs like this too:
  win = apis.BrowserWindow

  win.events.length
  // => 25

  win.events[0]
  // {
  //   "name": "page-title-updated",
  //   "description": "Emitted when the document...",
  //   "returns": [
  //     {
  //       "name": "event",
  //       "type": "Event"
  //     }
  //   ]
  // }

  win.instanceMethods[20]
  // {
  //   name: 'setSize',
  //   signature: '(width, height[, animate])'
  // }
})

How It Works

The linter starts with a list of all the API names as seed data.

Each API's structure is inferred by parsing its raw markdown documentation from the electron repo. The electron-docs module abstracts away the challenges of fetching file contents in bulk.

Electron's API documentation adheres to Electron Coding Style and the Electron Styleguide, so its content can be programmatically parsed. To make the content easy to parse, the raw markdown is converted to HTML using marky-markdown-lite, which returns a cheerio DOM object that can be queried and traversed using familiar CSS selectors.

The result is an array of API objects. The following metadata is included for each API, where appropriate:

  • name
  • description
  • type (Class or Module)
  • process (main, renderer, or both)
  • methods
  • events
  • static methods (aka class methods)
  • instance events
  • instance methods
  • instance properties
  • website URL
  • GitHub repository URL

Related Things and Prior Art

TypeScript Definitions

A lot of people want an up-to-date TypeScript definition file for Electron.

Dependencies

  • cheerio: Tiny, fast, and elegant implementation of core jQuery designed specifically for the server
  • clean-deep: Remove falsy, empty or nullable values from objects
  • decamelize: Convert a camelized string into a lowercased one with a custom separator: unicornRainbow โ†’ unicorn_rainbow
  • dedent: An ES6 string tag that strips indentation from multi-line strings
  • electron-docs: Fetch Electron documentation as raw markdown strings
  • keyed-array: Recursively add named keys to arrays of objects
  • lodash.pick: The lodash method _.pick exported as a module.
  • lodash.sum: The lodash method _.sum exported as a module.
  • marky-markdown-lite: A version of marky-markdown that does less
  • minimist: parse argument options
  • ora: Elegant terminal spinner
  • path-exists: Check if a path exists
  • pify: Promisify a callback-style function
  • revalidator: A cross-browser / node.js validator powered by JSON Schema
  • semver: The semantic version parser used by npm.
  • to-markdown: HTML-to-Markdown converter

Dev Dependencies

  • chai: BDD/TDD assertion library for node.js and the browser. Test framework agnostic.
  • mocha: simple, flexible, fun test framework
  • rimraf: A deep deletion module for node (like rm -rf)
  • standard: JavaScript Standard Style

License

MIT

electron-docs-linter's People

Contributors

ckerr avatar dependabot[bot] avatar hokein avatar kevinsawicki avatar marshallofsound avatar poiru avatar samuelmaddock avatar timfish avatar zeke avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.