2.11.96 • Published 12 months ago

@kollorg/deleniti-iure v2.11.96

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

@kollorg/deleniti-iure

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 @kollorg/deleniti-iure:

$ npm install @kollorg/deleniti-iure --save-dev

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

forEachCSSStyleDeclarationECMAScript 2019toReversedpyyamlstringifyargvtraverseclientjson-schema-validationpackage managerpropertypicomatchcode pointsescapepromiseassertastformattingclassnamesairbnbES2015find-upfromistanbulconcatresolveaccessorES5process256make diroptimizerstructuredCloneRxObject.keysglobal this valuefunctionsrobustdirectoryterminalcloudwatchspinnerinspectcjkclassnamecallbackglacieres2016rdsexpresshasOwnenvironmentequallook-uptelephonewgetcurlspawnObject.getPrototypeOfBigInt64Arraybannerperformanceposecloudfrontes-shimsgenericsfpsutilttylocalcontainspreprocessorsomeserializereusepatchcomparebundlerinstallUnderscorephonefunctionaltesterfile systemeslintconfigsuperstructsidecommandReactiveXidnodetoolkit3dES2022effect-tsroute53shimcolumnsdom-testing-librarytermreversepluginonceregularbusyes-abstractglobalsslicees2017windowarraystyleguideES3isConcatSpreadableidleTypeScriptgroupvpcregular expressionsunicoderegexprfc4122queryTypedArrayworkerArray.prototype.includescolorgitignoreruntimejestincludesJSONserializeremojivestfastgetterfindLastIndexschemacallbindECMAScript 6cloudformationhelpersleteventEmitterstoragegatewayhooksjQueryassertscolumnsearchformssymboldiffHyBiECMAScript 2017awesomesaucevalidatematchescryptocircularparseproxypropertiestypescripti18nuser-streamss3offsetcolour6to5karmadeep-clonecall-boundio-tsrssgroupByzod@@toStringTagrmregular expressionprotonpmignorefeedeslintpluginArraycharacterprefixES6transpilerfnmatchjasminevarsWebSocketentriesnodejsdefineimmerfscacheyamlsharedarraybufferajaxarraybufferpathsortedObject.assignobjflatjsonxhrtypeofStyleSheetfindregular-expressionRFC-6455l10nfunctionassertionfoldermakedir$.extendpropshellES2019browserestreeaccessibilitydropPushshamUint16ArrayapollodateECMAScript 2023compilerstringspringsymbolsemitprivate dataUint8Arrayrm -rffilterworkspace:*Object.valuescloudsearchjapanesetouchwhatwgReflect.getPrototypeOfloggingfastcopyparentcharactersreact posereadablestreamRxJStypanionexecfilejson-schemaforkfastcloneArrayBuffer#slicehashreducetypedarrayFloat32ArrayformquotebabeltoSortedURLhttpstreamebsprotobuflengthES2016flattenrequesttapeprotocol-buffersfast-deep-clonetypedsinatrauninstallreadabletranspileregexfetchIteratorrecursivesharedrulesmapsesreduxdataviewanimationcreatenegativefastifyomitfast-copynamespnpm9ECMAScript 2021bufferredactnameclassesbabel-coreenvthreewarningreworkiterateweaksetECMAScript 2016Mapdeep-copyWeakMaptypedarrayswaittypesafebyteconsumeupdefinePropertyArray.prototype.findLastIndexloggerframerfindupgraphqlignorepurehas-own__proto__byteOffsetjsdomECMAScriptiteratorconcatMapECMAScript 3setnativefast-deep-copysubprocessprototypemomentwalkmetadatayupamazonsyntaxerrorprivatecommandernopeweakmapspeedArray.prototype.flatsetterisutilitieschaichromiumes6immutabletrimLeftes8libphonenumberqueueMicrotaskelectrontakea11ydescriptorsfullwidthtc39logxmlajvidentifiersfindLastbdddeepcopyerrorprunegesturesemrobjectoptimistvisualelbWeakSetredirectkeysefficientchinesepoint-freesetPrototypeOfloadingjshintjsendpointextendprettyrmdirlocationtoArraymanagerponyfilltestieUint8ClampedArrayartselfstylestypees5flagvalueString.prototype.trimObjectes2018utilsbindES2021removearktypelanguageclass-validatorcheckObject.fromEntriesBigUint64Arraystringifierswfcollection.es6WebSocketschromejsdifftsinstallertransformReactiveExtensionsgetoptasterisksfull-widthdataViewsource mapreversedSystem.globalPromiseArrayBufferindicatorcssargumentdeleteinstrumentationcommand-linecollectionhasbuffersautoscalingredux-toolkitconsolebundlingqueueshrinkwrapexpressionbrowserslistboundES2018es-shim APIjsxhelperinferencetoStringTagassigniamtslibECMAScript 2020sameValueZeroglobreadlruYAMLstyle.envlistenerseventsespreedependency managerwritabletacitacornglobaldotenvnpmtapArray.prototype.flattenlinkdescriptorfullrestfulworkflowsafedependenciesrm -frcoerciblelastformatInt16ArrayawsArrayBuffer.prototype.slicecall-bindcomputed-typescloudtrailexecutewhichES2023ECMAScript 2018String.prototype.matchAllarraysESnextinternal slotkeyurlUint32ArrayFloat64ArraypolyfillmobileeverywebmochadescriptiontostringtagSetgdpransiMicrosoftsimpledbes7positiveenvironmentsdragchildsuperagentmodulesfiletypeerrormonorepoSymbol.toStringTagimportmovestreamsfantasy-landdeepinputESkoreanzxspinnerssettingsvariablesmatchAllStreamcurriedxtermStreamsminimalrapidpopmotionreact-hooksparentsform-validationES8binviewexecapiclonecoveragelockfilepushquerystringec2routertrimenumerablemkdirpvalidationscheme-validationbrowserlistextrapackagemapreducestarterFunction.prototype.namecalltyped arraywafcensorconfiguuidutil.inspectfunction.lengthreactrgbdeepcloneserializationInt32ArrayparsersnsvarAsyncIteratorwalkingcodessortcore-jspino
2.11.96

12 months ago

2.11.94

12 months ago

2.11.95

12 months ago

2.11.93

12 months ago

2.11.91

12 months ago

2.11.92

12 months ago

2.10.91

1 year ago

2.10.90

1 year ago

2.9.90

1 year ago

2.9.89

1 year ago

2.9.88

1 year ago

2.9.87

1 year ago

2.9.86

1 year ago

2.9.85

1 year ago

2.9.84

1 year ago

2.9.83

1 year ago

2.9.82

1 year ago

2.9.81

1 year ago

2.9.80

1 year ago

2.9.79

1 year ago

2.9.78

1 year ago

2.9.77

1 year ago

2.9.76

1 year ago

2.9.75

1 year ago

1.9.75

1 year ago

1.9.74

1 year ago

1.9.73

1 year ago

1.9.72

1 year ago

1.9.71

1 year ago

1.9.70

1 year ago

1.9.69

1 year ago

1.9.68

1 year ago

1.9.67

1 year ago

1.9.66

1 year ago

1.9.65

1 year ago

1.9.64

1 year ago

1.9.63

1 year ago

1.9.62

1 year ago

1.9.61

1 year ago

1.8.61

1 year ago

1.8.60

1 year ago

1.8.59

1 year ago

1.8.58

1 year ago

1.8.57

1 year ago

1.8.56

1 year ago

1.8.55

1 year ago

1.7.55

1 year ago

1.7.54

1 year ago

1.6.54

1 year ago

1.6.53

1 year ago

1.6.52

1 year ago

1.5.52

1 year ago

1.4.52

1 year ago

1.4.51

1 year ago

1.4.50

1 year ago

1.4.49

1 year ago

1.4.48

1 year ago

1.4.47

1 year ago

1.4.46

1 year ago

1.3.46

1 year ago

1.3.45

1 year ago

1.3.44

1 year ago

1.3.43

1 year ago

1.3.42

1 year ago

1.3.41

1 year ago

1.3.40

1 year ago

1.3.39

1 year ago

1.3.38

1 year ago

1.3.37

1 year ago

1.3.36

1 year ago

1.3.35

1 year ago

1.3.34

1 year ago

1.3.33

1 year ago

1.3.32

1 year ago

1.3.31

1 year ago

1.3.30

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.3.25

1 year ago

1.2.25

1 year ago

1.1.25

1 year ago

1.1.24

1 year ago

1.1.23

1 year ago

1.1.22

1 year ago

1.1.21

1 year ago

1.1.20

1 year ago

1.1.19

1 year ago

1.1.18

1 year ago

1.1.17

1 year ago

1.1.16

1 year ago

1.1.15

1 year ago

1.1.14

1 year ago

1.1.13

1 year ago

1.1.12

1 year ago

1.1.11

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

1.0.0

1 year ago