• Stars
    star
    157
  • Rank 238,399 (Top 5 %)
  • Language
    TypeScript
  • License
    MIT License
  • Created about 7 years ago
  • Updated about 2 months ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

A project-wide js-linting tool

stricter

Renovate enabled Build Status npm version Coverage Status

A project-wide js-linting tool

Installation

yarn add stricter --dev

Usage

yarn stricter

You can run yarn stricter --help for help.

Configuration

Stricter uses stricter.config.js to read configuration. The configuration file will be resolved starting from the current working directory location, and searching up the file tree until a config file is (or isn't) found.

Sample configuration

module.exports = {
    root: 'src',
    rulesDir: 'rules',
    exclude: /\.DS_Store/,
    plugins: ['tangerine'],
    resolve: {
        modules: [path.resolve(__dirname, 'src'), 'node_modules'],
    },
    rules: {
        'hello-world-project': {
            level: 'error'
        },
        'stricter/unused-files': [{
            level: 'warning',
            include : [/foo\.*/, /bar\.*/],
            exclude : (i) => i.includes('testFolder'),
            config: {
                entry: [
                    /foo\.eslintrc\.js/,
                    /foo\.*\.md/,
                    /foo\/bar\/index\.js/,
                    /foo\/baz\/index\.js/,
                ],
                relatedEntry: [
                    /foo\.*spec\.js/,
                    /foo\.*test\.js/,
                    /foo\.*story\.js/,
                ]
            }
        }],
        'stricter/circular-dependencies': [{
            level: 'error',
            config: {
                checkSubTreeCycle: true,
                registries: ['**/foo/bar', 'baz'],
            },
        }],
        'tangerine/project-structure': {
            level: 'error',
            config: { ... },
        }
    }
}

Description

root - string required, root folder for the project.

rulesDir - string | string[], folder(s), containing custom rules. Rule files need to follow naming convention <rulename>.rule.js. They will be available for configuration as <rulename>.

exclude - RegExp | RegExp[] | Function, regular expressions to exclude files, uses relative path from root or function accepting relative path and returning boolean

plugins - string[], packages that contain third-party rule definitions that you can use in rules. See Plugins for more details.

resolve - Object, if you are using webpack, and you want to pass custom resolution options to stricter, the options are passed from the resolve key of your webpack configuration.

rules - required, an object containing configuration for rules.

The keys should be rule names and values should be an object, array of objects or a function. Arrays will result in the rule being executed once per each entry in the array, see rule functions for more info on that syntax. The objects (RuleObject) should be of the form:

  • level - error | warning | off, log level
  • include - RegExp | RegExp[] | Function, regular expressions to match files, uses relative path from root or function accepting relative path and returning boolean
  • exclude - RegExp | RegExp[] | Function, regular expressions to exclude from matched files, uses relative path from root or function accepting relative path and returning boolean
  • config - any, config to be passed into rule

packages - string[], an array of globs that match paths to packages if you are in a multi-package repo. This can be used to override the default list of packages that are provided to rules configured using a function.

Rule functions

The default way of configuring rules is to provide objects, however, each rule value may also be a function that returns an object instead. This provides an easy way to configure rules designed to be executed against each package separately in a monorepo.

Signature: (args: { packages: string[] }) => RuleObject | RuleObject[]

where packages is a list of package directory paths in your project that are automatically detected by searching for package.json's in sub-directories, i.e. */**/package.json. To override where packages are searched, you can use the top-level packages config to provide an array of globs instead. For example, this could be sourced from the yarn workspaces field in your project's root package.json.

E.g.

module.exports = {
    ...
    rules: {
        'package-structure': ({ packages }) => packages.map(pkg => ({
            level: 'error',
            config: {
                pkgRoot: pkg,
            },
        })),
        'rule-that-does-not-need-to-execute-multiple-times': {
            level: 'error',
            ...
        }
    },
    ...
}

Here, the package-structure rule enforces a specific structure for a package and takes the root path of the package as a config argument. In a single-package repo, the rule can just use the object syntax and specify the root path of the project as the package root. However, in a multi-package repo this rule should be executed against each package separately rather than once at the root of the project so the function syntax can be used.

Default rules

stricter/circular-dependencies

Checks for circular dependencies in the code. Has a configuration to additionally check for cycles on folder level with ability to exclude particular directory from check by providing path to it in registries.

'stricter/circular-dependencies': {
    config: {
        checkSubTreeCycle: Boolean, // true to check for folder-lever cycles
        registries?: string[] | string, // Optional: values should be a glob
    }
}

stricter/unused-files

Checks for unused files. entry - application entry points. Usually these files are mentioned in entry part of webpack config or they are non-js files you want to keep (configs, markdown, etc.) relatedEntry - related entry points, they are considered used only if any of its dependencies are used by an entry or its transitive dependencies. Usually these are tests and storybooks.

'stricter/unused-files': {
    config: {
        entry: RegExp | RegExp[] | Function; // if function, will get file path as an argument
        relatedEntry: RegExp | RegExp[] | Function; // if function, will get file path as an argument
    }
}

Custom rules

A rule is a javascript module that exports an object that implements the following interface

interface RuleDefinition {
    onProject: ({
        config?: { [prop: string]: any; };
        dependencies: {
            [fileName: string]: string[];
        };
        files: {
            [fileName: string]: {
                ast?: () => any;
                source?: string;
            };
        };
        rootPath: string;
        include?: RegExp | RegExp[] | Function;
        exclude?: RegExp | RegExp[] | Function;
    }) => (string | { message: string; fix?: () => void; })[];
}

onProject will be called once with files and dependencies calculated for current project.

rootPath is an absolute path to project root.

config is an optional object that may be specifified in configuration.

onProject should return an array of objects, describing violations and their fixes, or an empty array if there is none.

include value of include from the rule

exclude value of exclude from the rule

CLI

Options:
  --help          Show help                                            [boolean]
  --version       Show version number                                  [boolean]
  --config, -c    Specify config location                               [string]
  --reporter, -r  Specify reporter        [choices: "console", "mocha", "junit"]
  --rule          Verify particular rule                                 [array]
  --clearCache    Clears cache
  --fix           Apply fixes for rule violations

Plugins

Stricter supports consuming rule definitions from other packages by specifying them in the plugins field of your stricter config.

The package names of plugins must be named stricter-plugin-<name>, e.g. stricter-plugin-tangerine. This guarantees unique rule names across different plugins.

Configuration

In the plugins field, you can specify the plugin using its short name <name> or its long form stricter-plugin-<name>. You can then enable and configure rules from a plugin by specifying the rules in the rules field.

When configuring rules from a plugin, they must be prefixed by their short plugin name <name>/<ruleName>, e.g. tangerine/project-structure.

e.g.

// stricter.config.js
module.exports = {
    root: '.',
    plugins: ['tangerine'],
    rules: {
        'tangerine/project-structure': {
            level: 'error',
            config: {...},
        }
    }
}

Creating plugins

To create a stricter plugin, ensure the package name is of the format stricter-plugin-<name>.

The main file of the package should then export a rules key that contains the rule definitions you wish to provide.

e.g.

module.exports = {
    rules: {
        'project-structure': {
            onProject: (...) => {...}
        },
        'another-rule': {
            onProject: (...) => {...}
        }
    }
}

Note that the rule names should not be prefixed when defining them inside the plugin, they are only prefixed when specifying them in configuration.

Pre-configured plugin rules

Rules provided by a plugin are not enabled by default, they must be configured by the end-user. If you would like to provide a preset configuration of rules provided by your plugin, simply export your preset configuration under a certain key. Consumers can then import that configuration and spread it into the rules field of their stricter config.

E.g.

Plugin

// stricter-plugin-tangerine/index.js
module.exports = {
    // This key can be arbitrarily named
    config: {
        'tangerine/project-structure': {
            level: 'error',
            config: {
                '.': {
                    'package.json': { type: 'file' },
                    'src': { type: 'dir' }
                }
            }
        }
    },
    rules: {
        'project-structure': {
            onProject: (...) => {...}
        },
    }
}

Stricter config

// stricter.config.js

// This import key `config` must match what is exported by the plugin
const { config: tangerineConfig } = require('stricter-plugin-tangerine');

module.exports = {
    root: '.',
    plugins: ['tangerine'],
    rules: {
        ...tangerineConfig,
    },
};

Exposed utilities

parseDependencies

Parses files and returns an object, containing filenames as keys and array of their dependencies as values.

const parseDependencies = (
    files: string[],
    { useCache = false, resolve = {} } = { useCache: false, resolve: {} }
): {
    [fileName: string]: string[];
}

useCache - pass true to leverage stricter filesystem cache
resolve - Object, if you are using webpack, and you want to pass custom resolution options to stricter, the options are passed from the resolve key of your webpack configuration

usage:

const { parseDependencies } = require('stricter');
const dependencies = parseDependencies(['foo.js', 'bar.js']);

Debugging

It helps to use src/debug.ts as an entry point for debugging. A sample launch.json for VS Code might look like

{
    "version": "0.2.0",
    "configurations": [
        {
            "name": "Current TS File",
            "type": "node",
            "request": "launch",
            "args": ["${relativeFile}"],
            "env": { "TS_NODE_FILES": "true" },
            "runtimeArgs": ["-r", "ts-node/register"],
            "cwd": "${workspaceRoot}"
        }
    ]
}

More Repositories

1

react-beautiful-dnd

Beautiful and accessible drag and drop for lists with React
JavaScript
33,330
star
2

pragmatic-drag-and-drop

Fast drag and drop for any experience on any tech stack
TypeScript
9,523
star
3

jest-in-case

Jest utility for creating variations of the same test
JavaScript
1,056
star
4

react-sweet-state

Shared state management solution for React
JavaScript
870
star
5

escalator

Escalator is a batch or job optimized horizontal autoscaler for Kubernetes
Go
663
star
6

github-for-jira

Connect your code with your project management in Jira
TypeScript
626
star
7

prosemirror-utils

βš’ Utils library for ProseMirror
TypeScript
479
star
8

nucleus

A configurable and versatile update server for all your Electron apps
TypeScript
396
star
9

docker-chromium-xvfb

Docker image for running browser tests against headless Chromium
Dockerfile
385
star
10

gostatsd

An implementation of Etsy's statsd in Go with tags support
Go
380
star
11

smith

Smith is a Kubernetes workflow engine / resource manager
Go
287
star
12

babel-plugin-react-flow-props-to-prop-types

Convert Flow React props annotation to PropTypes
JavaScript
234
star
13

better-ajv-errors

JSON Schema validation for Human πŸ‘¨β€πŸŽ€
JavaScript
233
star
14

browser-interaction-time

⏰ A JavaScript library (written in TypeScript) to measure the time a user is active on a website
TypeScript
217
star
15

gajira

GitHub Actions for Jira
199
star
16

extract-react-types

One stop shop for documenting your react components.
JavaScript
179
star
17

data-center-helm-charts

Helm charts for Atlassian's Data Center products
Java
155
star
18

bazel-tools

Reusable bits for Bazel
Starlark
113
star
19

gajira-login

Jira Login GitHub Action
JavaScript
98
star
20

terraform-provider-artifactory

Terraform provider to manage Artifactory
Go
89
star
21

build-stats

πŸ† get the build stats for pipelines πŸ†
TypeScript
81
star
22

dc-app-performance-toolkit

Atlassian Data Center App Performance Toolkit
Python
75
star
23

kubetoken

Kubetoken
Go
74
star
24

koa-oas3

Request and response validator for Koa using Open API Specification
TypeScript
73
star
25

1time

Lightweight, thread-safe Java/Kotlin TOTP (time-based one-time passwords) and HOTP generator and validator for multi-factor authentication valid for both prover and verifier based on shared secret
Kotlin
68
star
26

gajira-transition

JavaScript
59
star
27

gajira-create

JavaScript
58
star
28

sketch-plugin

Design your next Atlassian app with our component libraries and suite of Sketch tools πŸ’Ž
JavaScript
57
star
29

go-sentry-api

A go client for the sentry api https://sentry.io/api/
Go
50
star
30

themis

Autoscaling EMR clusters and Kinesis streams on Amazon Web Services (AWS)
JavaScript
48
star
31

gajira-todo

JavaScript
46
star
32

jira-cloud-for-sketch

A Sketch plugin providing integration with JIRA Cloud
JavaScript
45
star
33

gajira-find-issue-key

JavaScript
43
star
34

oas3-chow-chow

Request and response validator against OpenAPI Specification 3
TypeScript
42
star
35

validate-npm-package

Validate a package.json file
JavaScript
38
star
36

gajira-cli

JavaScript
38
star
37

conartist

Scaffold out and keep all your files in sync over time. Code-shifts for your file system.
JavaScript
34
star
38

gajira-comment

JavaScript
33
star
39

jira-github-connector-plugin

This project has been superseded by the JIRA DVCS Connector
JavaScript
30
star
40

voyager

Voyager PaaS
Go
29
star
41

atlaskit-framerx

[Unofficial] Atlaskit for Framer X (experimental)
TypeScript
28
star
42

jira-actions

Kotlin
27
star
43

sourcemap

Java
24
star
44

asap-authentication-python

This package provides a python implementation of the Atlassian Service to Service Authentication specification.
Python
23
star
45

go-artifactory

Go library for artifactory REST API
Go
23
star
46

vscode-extension-jira-frontend

JavaScript
18
star
47

ssh

Kotlin
16
star
48

jira-performance-tests

Kotlin
16
star
49

homebrew-tap

This repository contains a collection of Homebrew (aka, Brew) "formulae" for Atlassian
Ruby
16
star
50

atlassian-connect-example-app-node

TypeScript
15
star
51

docker-fluentd

Docker image for fluentd with support for both elasticsearch and kinesis
Makefile
11
star
52

infrastructure

Kotlin
11
star
53

omniauth-jira

OmniAuth strategy for JIRA
Ruby
11
star
54

jenkins-for-jira

Connect your Jenkins server to Jira Software Cloud for more visibility into your development pipeline
TypeScript
11
star
55

redis-dump-restore

Node.js library to dump and restore Redis.
JavaScript
10
star
56

fluent-plugin-kinesis-aggregation

fluent kinesis plugin shipping KPL aggregation format records, based on https://github.com/awslabs/aws-fluent-plugin-kinesis
Ruby
10
star
57

rocker

Little text UI for docker
Rust
9
star
58

hubot-stride

JavaScript
9
star
59

graphql-braid

9
star
60

copy-pkg

Copy a package.json with filters and normalization
JavaScript
8
star
61

gray-matter-loader

Webpack loader for extracting front-matter using gray-matter - https://www.npmjs.com/package/gray-matter
JavaScript
8
star
62

jsm-integration-scripts

Jira Service Management Integration Scripts
Python
8
star
63

autoconvert

TinyMCE plugin for Atlassian Autoconvert
JavaScript
8
star
64

less-plugin-inline-svg

A Less plugin that allows to inline SVG file and customize its CSS styles
JavaScript
7
star
65

aws-infrastructure

Kotlin
7
star
66

jira-hardware-exploration

Kotlin
6
star
67

report

HTML
6
star
68

virtual-users

Kotlin
6
star
69

docker-infrastructure

Kotlin
6
star
70

jobsite

Tools for working with workspaces as defined by Yarn, Lerna, Bolt, etc.
JavaScript
5
star
71

git-lob

Experimental large files in Git (discontinued, use git-lfs instead)
Go
5
star
72

ansible-ixgbevf

4
star
73

concurrency

Kotlin
4
star
74

jvm-tasks

Kotlin
4
star
75

ssh-ubuntu

Kotlin
4
star
76

jpt-example-btf

Java
3
star
77

gojiid

A Goji Middleware For adding Request Id to Context
Go
3
star
78

jira-software-actions

Kotlin
3
star
79

workspace

Kotlin
2
star
80

putty-sourcetree-fork

A fork of PuTTY used by Sourcetree
C
2
star
81

atlassian-connect-example-app-python

Python
2
star
82

atlassian-connect-example-app-java

Java
2
star
83

jec

JEC Client source codes and installation packages
Go
2
star
84

nadel-graphql-gateway-demo

Nadel GraphQL Gateway Demo app
HTML
1
star
85

parcel-stress-test

JavaScript
1
star
86

homebrew-bitbucket

A collection of pinned versions of dependencies for Bitbucket
Ruby
1
star
87

frontend-guides

1
star
88

tangerine-state-viewer

Visual Studio Code extension to facilitate tangerine state navigation
TypeScript
1
star
89

uniql-es

JavaScript
1
star
90

jasmine-http-server-spy

Creates jasmine spy objects backed by a http server.
CoffeeScript
1
star
91

packit-cli

CLI tool for creating package based architecture for enterprise frontend applications.
JavaScript
1
star
92

fluent-plugin-statsd_event

Fluentd plugin for sendind events to a statsd service
Ruby
1
star
93

github-packages-test

Test repo to verify artifact delivery pipeline
Kotlin
1
star
94

org.eclipse.jgit-atlassian

Java
1
star
95

jces-1209

Benchmark for Cloud and DC
Kotlin
1
star
96

webvieweventtest

TypeScript
1
star
97

quick-303

Cloud vs DC
Kotlin
1
star