Skip to content

Commit

Permalink
Make example folder self-contained (#340)
Browse files Browse the repository at this point in the history
* example: npm init -y

* example: Mark package as private

* example: npm i -D schemalint

* example: Add npm scripts and update README

* example: Specify import types

* Delete npm scripts that is related to example

* Update example configuration in README

* example: Use "*" version
  • Loading branch information
orangain committed Feb 11, 2024
1 parent 0cfc83f commit a905e0e
Show file tree
Hide file tree
Showing 7 changed files with 836 additions and 11 deletions.
7 changes: 4 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ $ npx schemalint
Here is an example configuration file:

```javascript
/** @type {import("schemalint").Config } */
module.exports = {
// Connection configuration. See: https://node-postgres.com/apis/client
connection: {
Expand All @@ -40,12 +41,12 @@ module.exports = {
charset: "utf8",
},

// Schemas to lint.
// Schemas to be linted.
schemas: [{ name: "public" }],

// Rules to be checked. The key is the rule name and the value is an array
// whose first value is the severity (only "error" is supported) and the
// rest are rule-specific parameters.
// whose first value is the severity ("error" to enable the rule, "off" to
// disable it) and the rest are rule-specific parameters.
rules: {
"name-casing": ["error", "snake"],
"name-inflection": ["error", "singular"],
Expand Down
3 changes: 2 additions & 1 deletion example/.schemalintrc.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
/** @type {import('schemalint').Config } */
module.exports = {
connection: {
host: 'localhost',
Expand All @@ -8,7 +9,7 @@ module.exports = {
port: 54321,
},

plugins: ['./example/custom-rules'],
plugins: ['./custom-rules'],

rules: {
'identifier-naming': ['error'],
Expand Down
8 changes: 4 additions & 4 deletions example/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,16 +12,16 @@ I've created a Docker image that hosts it so if you have Docker installed, you c
npm run start-example-db
```

First, run the build script in this folder with:
First, run the install command in this folder with:

```
npm run build
npm install
```

Then, run the config file in this folder with:
Then, run the schemalint using the config file `schemalintrc.js` in this folder with:

```
npm run run-example
npm run lint:schema # or just `npx schemalint`
```

You should see output like this:
Expand Down
1 change: 1 addition & 0 deletions example/custom-rules/identifierNaming.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
// This example rule will enforce primary key columns be named like this: tablename_id

/** @type {import('schemalint').Rule} */
const identifierNaming = {
name: 'identifier-naming',
docs: {
Expand Down
Loading

0 comments on commit a905e0e

Please sign in to comment.