Git Product home page Git Product logo

boll's Introduction

boll

Lint the whole repo.

Getting started

Install

To install, add @boll/cli as a dev dependency to your package with your package manager of choice.

npm install --save-dev @boll/cli

Configure

Next, run the init command to generate a configuration file that will be used when boll runs.

npx boll init

This command will create a configuration file called .boll.config.js in your current directory, implementing the recoommended configuration by default. It should look like the following.

"use strict";
module.exports = {
  extends: "boll:recommended"
};

Run

To run boll, simply pass the run command.

npx boll run

If everything is configured successfully and your project contains no boll violations, the command will exit with no output and an exit status of 0.

Next steps

Learn about configuring, tweaking, or adding rules in the docs.

Contributing

This project welcomes contributions and suggestions. Most contributions require you to agree to a Contributor License Agreement (CLA) declaring that you have the right to, and actually do, grant us the rights to use your contribution. For details, visit https://cla.opensource.microsoft.com.

When you submit a pull request, a CLA bot will automatically determine whether you need to provide a CLA and decorate the PR appropriately (e.g., status check, comment). Simply follow the instructions provided by the bot. You will only need to do this once across all repos using our CLA.

This project has adopted the Microsoft Open Source Code of Conduct. For more information see the Code of Conduct FAQ or contact [email protected] with any additional questions or comments.

boll's People

Contributors

brayovsky avatar dependabot[bot] avatar ecraig12345 avatar jcreamer898 avatar jdhuntington avatar jofrey-a-msft-production avatar kenotron avatar vipati avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar

boll's Issues

[Rule] It's not useful to have dependencies if peerDeps already are present

We need something akin to this (this is a shell script to FIX it, but we need something to prevent it in boll):

for p in packages/*/package.json;
do
  # if package has no peer dependency ignore it
  jq -e '.peerDependencies' $p >/dev/null || continue;
  # for each peer dependency
  for pd in $(jq '.peerDependencies | keys[]' $p);
  do
    # if package does not have a corresponding dependency, ignore it
    jq -e ".dependencies[$pd]" $p >/dev/null || continue;
    # remove peer dependency
    jq "delpaths([[\"peerDependencies\", $pd]])" $p > tmp
    mv tmp $p
    # if peerDependency field is not empty, ignore it
    test "0" = $(jq '.peerDependencies | keys | length' $p) || continue;
    # remove empty peerDependency field
    jq "delpaths([[\"peerDependencies\"]])" $p > tmp
    mv tmp $p
  done
done

TransitiveDependencyDetector should ignore type-only imports

Given

Package A

export interface Foo {}

Package B

import { Foo } from 'A';
{ "devDependencies": { "A": "0.0.0" }}

Expected

Runs with no errors

Actual

TransitiveDependencyDetector complains that 'A' is not properly declared as a dependency

Fix output for TransitiveDependencyDetector

Expected

[TransitiveDependencyDetector] /foo/index.ts:10 "@foo/bar" is used as a module import, but not listed as a dependency. (Either add as a direct dependency or remove usage.)

Actual

[TransitiveDependencyDetector] /foo/index.ts:0 "[object Object]" is used as a module import, but not listed as a dependency. (Either add as a direct dependency or remove usage.)

Allow rules to have the fix function

There are rules which we could potentially enable fixers for.

Imagine if the rule had an API such as...

const someRule = {
  check: async (filename, options) => {
    // make an errors array
    return errors;
  }, 
  fix: async (errors, options) => {
    // do some stuff to fix the error
  }
}

export const someRule;

This is similar to how manypkg works here...

And how eslint rules work as well such as here...

TransitiveDependencyDetector: Should ignore imports in `d.ts` files

Running boll with certain lib output containing d.ts files can result in output like:

ERR! [TransitiveDependencyDetector] D:\git\ooui\m\packages\excel-online-cardview\lib\webpack\resjsonBundlerWebpackPlugin.d.ts:0 "webpack" is used as a module import, but not listed as a dependency. (Either add as a direct dependency or remove usage.)

d.ts files contain type information only, are not executable files, and should be universally ignored in rules that apply to executable code.

Specifically here, any imports in d.ts files can be safely concluded to be types-only imports and should not be considered for certain rules, such as TransitiveDependencyDetector.

Create a reporter and some rules which can provide the compliance status of a set of checks

In order to help create a "pit of success" for best practices in a monorepo, let's create a standard set of "best practices" type rules.

Once the rules are created, let's also add a new reporter which can return return the results of running the monorepo checks. IN that weay, repository owners can run the boll monorepo best practices checks to see how their repo aligns.

Override ruleset glob in configuration

In my local configuration, I should be able to write:

{ ruleSets: {
  ruleName: {
    include: ['./src/**/*']
  }
} }

and it should entirely replace the patterns that the default glob implementation would run.

Update the docs with the new APIs from v3

There's several new pieces of functionality that need to be updated in the docs.

  • How to use addRule
  • How to use the bootstrap function of a plugin
  • Auto loading of plugins
  • There are two ways to run boll, at monorepo root or against individual packages

Unused dependency detector

For a given package, highlight any packages that are included but not used.

Would need to support a list of exemptions for globals that are ambient imports.

Support an array of extends

Similar to how eslint works, the "extends" option should be able to take an array, instead of only a single rule set.

NodeModulesReferenceDetector is too aggressive...

Many webpack.config.js module.rules loader configurations would have an explicit excludes of a /node_modules/ pattern. We should allow these kinds of references. I think maybe we should only have the detector deal with things inside a require() or import statement. This will make the rule not catch 100% of stuff, but it can at least allow the proper uses of these node_modules appearances. Alternative is to have disable-single-line kind of thing so that we don't have to disable the entire rule altogether.

Rule: rationale entries in package.json files

What?

For specific sections of package.json files, ensure that all dictionary entries have corresponding entries in a rationale section.

Why?

As JSON does not allow comments, it is difficult to annotate tricky or dangerous lines in package.json files. Content of certain sections (such as resolutions) often carry increased risk, and there is a desire to have inline annotations for other developers' benefits.

Rule specifics

The default configuration of the rule should cause a failure on the following package.json

{
  "name": "foo",
  "resolutions": {
    "transitive-package-1": "0.0.29",
  }
}

The failure should clarify that "a rationale entry for resolutions.transitive-package-1 was expected, but was not found".

The default configuration of the rule should succeed on this fixed version of the previous file:

{
  "name": "foo",
  "rationale": {
    "resolutions": {
      "transitive-package-1": "needed because of issue with dependency-package-2",
    }
  },
  "resolutions": {
    "transitive-package-1": "0.0.29",
  }
}

package.json files that have no need for a rationale entry (because of no declared resolutions for instance) should succeed as well.

Configuration options

  • rationaleRequiredList - a list of keys in package.json that require a corresponding entries in rationale.
    Default value: ['resolutions', 'workspaces.nohoist']

TransitiveDependencyDetector should allow references to node utilities in tests

Test files should be granted more permissive access to imports than product code.

For instance, this code is fine in a test:

import { promisify } from 'util';

However, would cause problems if packaged and evaluated in a browser.

This rule should handle these scenarios cleanly without the need for special cases or updates to manually maintained lists in the future.

Perhaps the cleanest solution is to not run this rule on files that are not "shipped" from a package. However, given multiple build pipelines (typescript, webpack, etc), it can be difficult to determine if a file actually ends up be exported.

Runner: make sure to only run boll against git-controlled files

We should have at least an option to only run the boll rules against git controlled files. Otherwise, we'll run into issues dealing with a repo that needs to move onto something that has a strict file access requirements like BuildXL. So, for example, it is not good to have a linter that is run all in parallel with no topological ordering that COULD access files that are built. This means that the boll linter does slightly DIFFERENT things against a repo that has been BUILT vs something that is CLEAN.

exclude/include should be inherited

Expected:

If I inherit a ruleset with an exclude directive and declare my own, the exclude settings should be merged.

Actual:

The downstream exclude setting takes over and becomes the only definition.

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.