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

tslint-tinypg

v2.0.2

Published

TSLint rules for TinyPg.

Downloads

431

Readme

tslint-tinypg

npm version travis build MIT license

TSLint rules to lint tinypg usage in TypeScript.

Background

When using tinypg with typescript, it's possible to reference a missing SQL file. It's easy to pass in an object with unused properties or to pass an object with missing properties. Using typescript's AST, we can find usages of tinypg and make sure that it is being used appropriately. In the future, we may be able to add more rules for other gotchas like SQL injection warnings or misuse of transactions.

Installing

npm install tslint-tinypg --save-dev

See the example tslint.json file for configuration.

Compability

  • tslint-tinypg 1.x.x is compatible with tslint 5.x.x.

TSLint Rules

The following rules are available:

Tinypg rules

no-unused-properties

This rule enforces that the object passed to a tiny .sql call must have every property used inside the SQL file.

This is typically an error because you think that you are using that property, but you actually aren't.

Given:

SELECT *
FROM user
WHERE user.name = :name

in users.fetch

import { TinyPg } from 'tinypg'

const db = new TinyPg({
   connection_string: 'postgres://postgres@localhost:5432/mydb',
   root_dir: __dirname + '/sql_files'
})

// NOT OK
db.sql('users.fetch', {
   name: 'Joe',
   enabled: false,
})

//OK
db.sql('users.fetch', {
   name: 'Joe',
})

no-missing-sql-file

This rule enforces all tiny calls to .sql reference a valid SQL file.

Given:

├── sql_files
│   ├── fetch_user.sql
│   └── users
│       └── fetch.sql
import { TinyPg } from 'tinypg'

const db = new TinyPg({
   connection_string: 'postgres://postgres@localhost:5432/mydb',
   root_dir: __dirname + '/sql_files'
})

// NOT OK
db.sql('users.create', {
   name: 'Joe',
})

//OK
db.sql('users.fetch', {
   name: 'Joe',
})

db.sql('fetch_user', {
   name: 'Joe',
})

Options

Sample Configuration File

Here's a sample TSLint configuration file (tslint.json) that activates all the rules:

{
  "rulesDirectory": ["./node_modules/tslint-tinypg/rules"],
  "rules": {

    // Tinypg rules
    "no-missing-sql-file": true,
    "no-unused-properties": true,
    "no-missing-properties": true
  }
}

How to contribute

For new features file an issue. For bugs, file an issue and optionally file a PR with a failing test. Tests are really easy to do, you just have to edit the *.ts.lint files under the test directory. Read more here about tslint testing.

How to develop

To execute the tests run yarn test. To release a new package version run yarn publish:patch, yarn publish:minor, or yarn publish:major.

Prior work

This work was originally inspired by vscode-tinypg. The template for this repo came from jonaskello/tslint-immutable.