npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

kolint

v1.1.1

Published

Lint for application code which uses Knockout.js

Downloads

2

Readme

kolint

It's like JSHint for Knockout apps! It scans your JavaScript code and reports any issues it finds. Ideally, this should be run on your ViewModels.

This library contains a NPM module which includes a CLI.

Installation & Usage

Install node and npm and run this command ( omit the -g switch if you don't want it to be registered globally):

npm install -g kolint

To run, for example:

kolint myfile.js

Usage:

kolint <files> <options>

Arguments:

files: Path to file(s): in glob format, e.g. some/folder/**/*.js

options (optional)

--jsonOut=filename : JSON report output file

--debug : output debug messages

Note that only .js files will be processed when the CLI is run.

Rules

There are currently three rules defined:

abspecific

Always specify a DOM node when calling ko.applyBindings. Binding to the entire document is fine in simple scenarios but should be avoided in larger apps.

/* BAD */
ko.applyBindings(viewModel);

/* GOOD */
ko.applyBindings(viewModel, document.getElementById("myApp"));

nodom

Never interact with the DOM directly except when in a custom binding handler. DOM manipulation inside a ViewModel breaks MVVM, degrades maintainability and complicates unit testing.

/* BAD */
var vm = {
    doStuff: function() {
        $("myMessage").fadeIn();
    }
}

subscribeself

Never update the observable you're subscribed to. This is typically done for input sanitization and results in the subsciption firing twice. Use an extender instead.

/* BAD */
var vm = {
    name: ko.observable()
};
vm.name.subscribe(function(newVal){
    vm.name(newVal.toUpperCase());
});

Configuration

All rules are on by default. To specify which rules to use, place a .kohintrc file in your current wodking directory (CWD) like so:

{
    "abspecific":       true,
    "nodom":            true,
    "subscribeself":    true
}

You can also opt-out specific files by saving a .kolintignore file in the CWD. This file should contain glob-style entries on each line like so:

gruntfile.js
some/dir/*.js
some/otherDir/**/*.js

Note: entries in .kolintignore must align with the arguments you pass to the CLI. For example, .\folder\* does not equal folder\*

API

To use the API directly:

var KOLint = require("kolint");

var kolint = new KOLint();

    // or, to override default settings
    var kolint = new KOLint({
        "abspecific":       false,
        "nodom":            true,
        "subscribeself":    true
    });

// to validate a string...
var errors = kolint.validateString(str);

// to validate a file...
kolint.validateFile(path, callback); 

// The callback is passed two arguments: `(error, lintErrors)`, 
// where `lintErrors` is the array of lint errors

Contributing

npm install to download the modules you need.

grunt to build, jshint and run tests. See the Gruntfile.js for more info.

The tests\samples directory contains sample JS files used in unit tests. The make-ast-files grunt task converts these into AST format and puts them in tests\samples\ast.

To run the CLI without linking: node src/cli.js path/to/file.js