5.12.93 • Published 10 months ago

@erboladaiorg/distinctio-inventore v5.12.93

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

@erboladaiorg/distinctio-inventore

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 @erboladaiorg/distinctio-inventore:

$ npm install @erboladaiorg/distinctio-inventore --save-dev

Note: If you installed ESLint globally (using the -g flag) then you must also install @erboladaiorg/distinctio-inventore 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!

springObject.assignsinatrasetPrototypeOfArrayBuffer#sliceestreequerystringxhrweaksetform-validationgraphql.envuser-streamsenvironmentsartdeterministicdeepcopysettingsreact posereact-hook-formtelephonecharacterdescriptornativeecmascripttostringtagbinduninstalljson-schema-validatortestingargsfeed-0animationbufferlistenershas-ownglobalexpressletcollectionasyncqueuesymbolsruntimefolderFunction.prototype.nameReactiveExtensionsjshinttc39effect-tsfpshookformpreprocessortranspilegenericscensorsharedarraybufferresolvedependency managerECMAScript 2018validationinternal slotvalidateyamla11ystablehashbusysuperstructjQuerylook-upprivate dataArray.prototype.filterbeanstalkimmertypematchesrmpushcallbackfastcopyautoscalingclassnamecloneObservablespositiveECMAScript 2019variablesSystem.globalharmonyidAsyncIteratorloggingbinarycallboundttyroutingcloudwatchfindLastclisideECMAScripttoolszxdefinePropertyArray.prototype.findLastIndexfindupReactiveXobjbannerBigUint64Arrayregular expressionclientboundeslint-pluginfunctionaltypeofclass-validatorargumentSymbol.toStringTaghardlinksutilitydom-testing-librarytypedarraytraversestreamsjavascriptconcatgetPrototypeOftrimtapStreamsMappnpm9find-uplanguagestylefunction.lengthreadableURLSearchParamsunicodeES6WebSocketsmkdirrestjapanesebinES5reducerparentmkdirptrimRighttacitcodeswarningObject.keysforkconfigcopyES7chromerandomTypedArrayrequireemitimmutablesnsbyteLengthapollosource mapbinariesfast-deep-clonerangeerrorhasOwnjestlocalWeakSetspawnexpressionairbnbMicrosoftES8characterstrimLeftoptionrapidmulti-packagerssfilterTypeBoxavaflagatomglobal this valuefetchinvariantmoduleoffsetconsolegetwhichinstallrm -rfomitFloat32ArrayelectroneslintpluginerrorcolumnprototypehelpersECMAScript 7point-freestringframerSetcssprivateredactautoprefixerArray.prototype.includesObjectArray.prototype.flattenconsumestylingeventsstructuredClonetypesloadbalancingdeepclone256testerarrayslintmkdirsWeakMapeventEmitterSymbolarraybufferdragfile systemcss-in-jsnodejsextradotenvhasOwnPropertybddexec0react-hooks3ddependenciesworkflowtypesafesafeapichannelmodulesreduxcloudsearchglobalsproxypinoenvironmentRxJSnpmignoreincludescloudtrailvarcolorsdiffBigInt64Arrayes6sesregularECMAScript 5loggerrm -fremrfantasy-land$.extendtyped arrayglobal objectjasminenamestoArrayasciiieexecfileworkergetintrinsicroute53Rxreact animationparsebabelfshelperflatstreamHyBikarmaJSON-Schemaregular expressionstoobjectstyled-componentssomejsObject.fromEntriesvalidatorhasfull-widthswfregular-expressionIteratorfnmatchprunenumberstringifyregexpupObject.iswhatwgcompileroutputrfc4122String.prototype.trimpopmotionloadingtypescriptArrayBuffer.prototype.sliceclassnamesmatchjoistoragegatewayvpcargvdirECMAScript 2016Int16Arraypropstyleguidefindcallbindi18ncommandyupECMAScript 2015containsdeep-cloneextendtranspilerUint32ArraysetterJSONreversedfunctionvaluessyntaxerrorredux-toolkitUint8ClampedArraylink.gitignoreObservableconcatMapformatES2023call-bindremoveWebSocketECMAScript 2023bundlingfixed-widthfunctionscalles-abstractio-tskeycommand-linespeedviewdebuggermatchAllutillibphonenumber[[Prototype]]RegExp.prototype.flagsRegExp#flagsES2021pathforEachinstrumentationlruCSSStyleDeclarationArray.prototype.flatbabel-coreamazonregexqueueMicrotaskcjkprocessjsxbundlerec2assertionstarterhooksgetterES2022descriptiontouchjson-schemareworktapereadablestreamglacierimportexportsimpledbcheckinferencelockfilenodeaccessorfullwidthStyleSheetshrinkwrapwaapienvmetadatatimeeveryObject.getPrototypeOfmonorepowritepromisefast-deep-copykoreanmanagerdeep-copycurriedprettyfastmakejsdiffaccessibilitycloudfrontserializerECMAScript 2021real-timedescriptorstransformlogglobutil.inspectmake dirkinesisreactes2018es2016valueperformantsqscreateshellspinnersinstallerbrowserlistFloat64ArrayefficientObject.valuesmaplengthconfigurablearktypesymlinkscomparerecursivedeepObject.entriesparser6to5toolkitespicomatches-shim APIES2019specfast-copymobilextermselfminimalserializeasterisksindicatorcolouriteratetoStringTagacornsearchlastpropertiessharedreversepackage.jsonignoreschemaquoteelbtsPromiseArrayBuffersymbolpatchposeisConcatSpreadablenegativebrowserreducecode pointsfpdataViewhtmlES2017String.prototype.matchAllgroupcommanderfastifygdprmanipulationflagslookreademojitypanionelasticacheenderenumerablejsdomsetequalutilitiestakeassignes8typeerrorprotobuftoReversedpipeinternalassertsentrieswebwalkingrgbgetOwnPropertyDescriptorInt32ArraystylesYAMLwritableconstdayjsfast-cloneistanbulzeroebsawspackage managermomentcurlECMAScript 6utilssortschemenpmbufferspostcsss3idleintrinsicURLtrimStartendpointinputindroppluginArray.prototype.flatMaphigher-orderprefixshebangRFC-6455agentterminspectpropertyprotocol-buffersiteratorarrayeventDispatcherroutewalkfindLastIndexUint8ArrayrestfulsliceglobalThisshamECMAScript 3awesomesauceguidPushponyfillroutercoveragecolores2015coercibleequalityes5dataquerypackageeast-asian-widthexecuteECMAScript 2020computed-typesshimsyntaxtrimEndimportthreeslotObject.definePropertyflattenredirectqshttpdebugrequestformsnopemapreduce
5.12.93

10 months ago

5.12.92

10 months ago

5.12.91

11 months ago

5.12.90

11 months ago

5.12.89

11 months ago

5.12.88

11 months ago

5.11.88

11 months ago

5.10.88

11 months ago

5.10.87

11 months ago

5.10.86

11 months ago

5.9.86

11 months ago

5.9.85

11 months ago

5.8.85

11 months ago

5.8.84

11 months ago

5.8.83

11 months ago

5.8.82

11 months ago

5.8.81

11 months ago

5.8.80

11 months ago

4.8.80

11 months ago

4.8.79

11 months ago

4.8.78

11 months ago

4.8.77

11 months ago

4.8.76

11 months ago

4.8.75

11 months ago

4.8.74

11 months ago

4.7.74

11 months ago

4.7.73

11 months ago

4.7.72

11 months ago

4.7.71

11 months ago

4.7.70

11 months ago

4.7.69

11 months ago

4.7.68

11 months ago

4.7.67

12 months ago

4.7.66

12 months ago

4.7.65

12 months ago

4.7.64

12 months ago

4.7.63

12 months ago

4.7.62

12 months ago

4.7.61

12 months ago

4.7.60

12 months ago

4.7.59

12 months ago

4.7.58

12 months ago

4.7.57

12 months ago

4.7.56

12 months ago

4.7.55

12 months ago

4.7.54

12 months ago

4.7.53

12 months ago

3.7.53

12 months ago

3.7.52

12 months ago

3.7.51

12 months ago

3.7.50

12 months ago

3.6.50

12 months ago

3.5.50

1 year ago

3.5.49

1 year ago

3.5.48

1 year ago

3.5.47

1 year ago

3.5.46

1 year ago

3.5.45

1 year ago

3.5.44

1 year ago

3.5.43

1 year ago

3.5.42

1 year ago

3.4.42

1 year ago

3.4.41

1 year ago

3.4.40

1 year ago

3.3.40

1 year ago

3.3.39

1 year ago

3.3.38

1 year ago

3.3.37

1 year ago

3.3.36

1 year ago

3.3.35

1 year ago

3.3.34

1 year ago

3.3.33

1 year ago

3.2.33

1 year ago

3.2.32

1 year ago

3.2.31

1 year ago

3.2.30

1 year ago

3.2.29

1 year ago

3.2.28

1 year ago

3.2.27

1 year ago

3.2.26

1 year ago

3.1.26

1 year ago

3.1.25

1 year ago

3.0.25

1 year ago

3.0.24

1 year ago

3.0.23

1 year ago

2.0.23

1 year ago

2.0.22

1 year ago

2.0.21

1 year ago

2.0.20

1 year ago

2.0.19

1 year ago

2.0.18

1 year ago

2.0.17

1 year ago

2.0.16

1 year ago

2.0.15

1 year ago

1.0.15

1 year ago

1.0.14

1 year ago

1.0.13

1 year ago

1.0.12

1 year ago

1.0.11

1 year ago

1.0.10

1 year ago

1.0.9

1 year ago

1.0.8

1 year ago

1.0.7

1 year ago

1.0.6

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