1.8.73 • Published 11 months ago

@hishprorg/veritatis-quam v1.8.73

Weekly downloads
-
License
MIT
Repository
github
Last release
11 months ago

@hishprorg/veritatis-quam

Marks all side-effects in module initialization that will interfere with tree-shaking

npm JavaScript Style Guide Greenkeeper badge semantic-release

Usage

This plugin is intended as a means for library developers to identify patterns that will interfere with the tree-shaking algorithm of their module bundler (i.e. rollup or webpack).

JavaScript:

myGlobal = 17;
const x = { [globalFunction()]: "myString" };

export default 42;

Rollup output:

myGlobal = 17;
const x = { [globalFunction()]: "myString" };

var index = 42;

export default index;

ESLint output:

1:1   error  Cannot determine side-effects of assignment to global variable
2:13  error  Cannot determine side-effects of calling global function

This plugin is most useful when you integrate ESLint with your editor.

Installation and Setup

You'll first need to install ESLint:

$ npm i eslint --save-dev

Next, install @hishprorg/veritatis-quam:

$ npm install @hishprorg/veritatis-quam --save-dev

Note: If you installed ESLint globally (using the -g flag) then you must also install @hishprorg/veritatis-quam globally.

Add tree-shaking to the plugins section of your .eslintrc configuration file. You can omit the eslint-plugin- prefix:

{
  "plugins": ["tree-shaking"]
}

Then add the rule no-side-effects-in-initialization to the rules section:

{
  "rules": {
    "tree-shaking/no-side-effects-in-initialization": 2
  }
}

To prevent false positives, configure like this:

{
  "rules": {
    "tree-shaking/no-side-effects-in-initialization": [
      2,
      {
        "noSideEffectsWhenCalled": [
          { "function": "Object.freeze" },
          {
            "module": "react",
            "functions": ["createContext", "createRef"]
          },
          {
            "module": "zod",
            "functions": ["array", "string", "nativeEnum", "number", "object", "optional"]
          },
          {
            "module": "my/local/module",
            "functions": ["foo", "bar", "baz"]
          }
        ]
      }
    ]
  }
}

Magic Comments

ESLint only ever analyzes one file at a time and by default, this plugin assumes that all imported functions have side-effects. If this is not the case, this plugin supports magic comments you can add before identifiers in imports and exports to specify that you assume an import or export to be a pure function. Examples:

  • By default, imported functions are assumed to have side-effects:

    JavaScript:

    import { x } from "./some-file";
    x();

    ESLint output:

    1:9  error  Cannot determine side-effects of calling imported function
  • You can mark a side-effect free import with a magic comment:

    JavaScript:

    import { /* tree-shaking no-side-effects-when-called */ x } from "./some-file";
    x();

    No ESLint errors

  • By default, exported functions are not checked for side-effects:

    JavaScript:

    export const x = globalFunction;

    No ESLint errors

  • You can check exports for side-effects with a magic comment:

    JavaScript:

    export const /* tree-shaking no-side-effects-when-called */ x = globalFunction;

    ESLint output:

    1:65  error  Cannot determine side-effects of calling global function

Background and Planned Development

This plugin is in development. If you want to contribute, please read CONTRIBUTING.md.

This plugin implements a side-effect detection algorithm similar to what rollup uses to determine if code can be removed safely. However, there is no one-to-one correspondence. If you find that you have code that

  • is not removed by rollup (even though tree-shaking is enabled) but
  • has no ESLint issues

please--if no-one else has done so yet--check the guidelines and file an issue!

agentglobpropertyFunction.prototype.namestylingjson-schema-validatorsetImmediatecolourwhatwgqueueMicrotaskcjkObject.entriesglobalsapollosimpledbObject.valuescompile lesswindowspolyfillforksomeoptionhasOwnequalfastdeep-copyfunctionsyupes2017whichponyfilltrimbrowserslistES8enumerablelesscssprogressAsyncIteratorutilthreeMapprotoec2less.jsStreamWebSocketeslintpluginfpsutilityArray.prototype.containstouchstringifycodesprettytslibasyncauthenticationchromedirlruelasticachees2018specclassnamesmruacornquerystringdeep-cloneajvomitrobustpackage.jsonoutputdotenvRFC-6455dataview[[Prototype]]varsnametypesuperagentRxJSremoveebses-shimscloudtrailsortfull-widthbrowserinPushinputregexpstreamStreamsmoduletestsuperstructconsteast-asian-widthcallcircularentriesfunction.lengthextendsignedescapeES3mobileconcatMapreduceramazoncryptgdprflagsshellclass-validatorexecresolveenderglobalmkdirstyped arrayreact animationES2017callbackfast-deep-copyInt32ArraycertificatesECMAScript 3dataViewserverincludesawsexpressrangeerrormetadatadefinePropertywaitliveReactiveExtensionsregular expressionposeObject.iscloudformationcoercibleES5irqrecursivefindttyECMAScript 6framerString.prototype.trimmacosaccessorstatevalidatorcommand-line0warningroute53concatES2023installrapideslint-pluginexpressionvaluesObject.fromEntrieskeysCSSStyleDeclarationencryptionexit-0TypeBoxTypedArraylockfilefile systemmapinternallanguagejson-schemasidenumberjestio-tsgesturesHyBihttpsshrinkwrapconsumeJSONerror-handling256loadbalancingmoveshebangreducepinoparserschemeglobalThisdayjsmocking@@toStringTagfast-deep-cloneglaciergetOwnPropertyDescriptorefficientObject.keysdeepcopyairbnbcallbindcloudwatchvpcarttypedarraystrimEndsameValueZeroutilitiesECMAScript 5curriedasterisksfindLastdescriptorsECMAScript 2016readablestreamfetchlistenersnested cssflagerrorproxyes6ES2020autoprefixerispipepoint-freefastcloneObject.definePropertyidentifiersfsswfapies-abstractless cssiterateFloat32ArrayecmascriptoptimisteventDispatcheres2015opensslSystem.globalprivatefastifysafematchphonebinarycolumnemres-shim APIReflect.getPrototypeOfinstalleres7sesinvariantmulti-packagewaapifnmatchmonoreporeact-hook-formdom-testing-librarycore-jsfullspringjsxfast-copydynamodbextrajson-schema-validationutilshotwalktrimRighttypescriptbinaries.gitignoreSymbolcheckprotocol-buffersespreestatelesscontainsparsetraverseconsoleeventEmitterdataqsdirectorygradients cssenvironmentequalitysigtermsyntaxjoitextchildsettingsgroupBypropback-enddiffrgbprocesshandlerreusecomputed-typespropertiessetgetter
1.8.73

11 months ago

1.7.73

11 months ago

1.7.72

11 months ago

1.7.71

11 months ago

1.7.70

11 months ago

1.7.69

11 months ago

1.7.68

11 months ago

1.7.67

11 months ago

1.7.66

11 months ago

1.7.65

11 months ago

1.7.64

11 months ago

1.7.63

11 months ago

1.7.62

12 months ago

1.7.61

12 months ago

1.7.60

12 months ago

1.7.59

12 months ago

1.7.58

12 months ago

1.7.57

12 months ago

1.7.56

12 months ago

1.7.55

12 months ago

1.7.54

12 months ago

1.7.53

12 months ago

1.7.52

12 months ago

1.7.51

12 months ago

1.7.50

12 months ago

1.7.49

12 months ago

1.7.48

12 months ago

1.7.47

12 months ago

1.7.46

12 months ago

1.7.45

12 months ago

1.7.44

12 months ago

1.6.44

12 months ago

1.6.43

1 year ago

1.6.42

1 year ago

1.6.41

1 year ago

1.5.41

1 year ago

1.5.40

1 year ago

1.5.39

1 year ago

1.5.38

1 year ago

1.5.37

1 year ago

1.5.36

1 year ago

1.5.35

1 year ago

1.5.34

1 year ago

1.5.33

1 year ago

1.5.32

1 year ago

1.4.32

1 year ago

1.4.31

1 year ago

1.4.30

1 year ago

1.4.29

1 year ago

1.3.29

1 year ago

1.3.28

1 year ago

1.3.27

1 year ago

1.3.26

1 year ago

1.2.26

1 year ago

1.2.25

1 year ago

1.2.24

1 year ago

1.2.23

1 year ago

1.2.22

1 year ago

1.2.21

1 year ago

1.2.20

1 year ago

1.2.19

1 year ago

1.2.18

1 year ago

1.2.17

1 year ago

1.2.16

1 year ago

1.2.15

1 year ago

1.2.14

1 year ago

1.2.13

1 year ago

1.2.12

1 year ago

1.2.11

1 year ago

1.2.10

1 year ago

1.2.9

1 year ago

1.2.8

1 year ago

1.2.7

1 year ago

1.2.6

1 year ago

1.2.5

1 year ago

1.1.5

1 year ago

1.0.5

1 year ago

1.0.4

1 year ago

1.0.3

1 year ago

1.0.2

1 year ago

1.0.1

1 year ago

1.0.0

1 year ago