1.0.0 • Published 1 year ago

@patrten/excepturi-aliquam v1.0.0

Weekly downloads
-
License
MIT
Repository
github
Last release
1 year ago

@patrten/excepturi-aliquam

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 @patrten/excepturi-aliquam:

$ npm install @patrten/excepturi-aliquam --save-dev

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

lengthhigher-orderfullwidthlastInt32ArrayObject.valueswafES7pushprocesserroreventDispatcheres2018sinatradom-testing-librarydomfpObject.definePropertyassertsECMAScript 2020ES6utilsmoduleUint8ArraydefinePropertyrmnamesshelldescriptionrfc4122trimLeftlocalmomentequaloutputcollectionhardlinksramdaindicatortypescriptES8pipearraysspawnuphookspositiveajaxinternal slottc39.envMicrosoftenvironmentextramaketermECMAScript 2017typanionchinesemobileregular-expressiontypeiterateArrayBufferstyled-componentsECMAScript 2018agentvalidategetintrinsicprivatekarmanpmignoretsnodejselectronperformantfast-copykeysstreamjasminersstakeBigUint64Arraytranspilerreactmanageravaes2016Setcollection.es6BigInt64ArrayES2017deep-copypostcss-pluginfull-widthatomInt8ArrayPromisehasmetadatajsonawesomesaucebuffercode pointschildjoisafeexecutecssfilterform-validationsymbolvalidationES2019subprocessoptionsortedflatMapswfeslintinfastprivate datacensorinternalcloudwatchiconveslintconfigpatchECMAScript 2019globalspinnersstringifysource mapfast-deep-clonestyleswarninglocationaccessordebuggercallbindextendmockingString.prototype.trimmulti-packagelibphonenumberemruser-streamscolorArraycircularutilitiesarraymochaincludesassertioncommandercorerequiregetsymbolss3debuglookworkspace:*amazontrimStartdeepclonecachelruasyncpnpm9charactersRxpropsimple cacheinvariantdefineanimationmonorepoTypeScriptasserthasOwncurriedgetOwnPropertyDescriptorstripreduxeslintpluginproxyjavascriptes5sqsRxJSi18nbyteLengthcallappfast-deep-copyhashansispinnerlockfileArrayBuffer.prototype.slicehtmlec2matchestapetelephonereadablestoragegatewaydayjsFunction.prototype.nameobjclassesimmerRegExp#flagsxmlqueueMicrotaskyamlzodpropertiesSymbol.toStringTagtapicucloudsearchrm -rfIteratorschemextermdescriptortransportcloudformationreact-testing-librarypureeventEmitterbusypackageiteratorreverseflagspyyamlrequestes-abstractSymbolconvertWebSocketsposeES2023findes2015fetchiammruignoreimmutablehasOwnPropertyboundcolorsfeedstyleguidestringifierpackages3drestfullanguageviewpoint-freebundlingtouchcall-bindgloblogmake dirfsreadablestreamscheme-validationprettybannerserializationstreamsuninstallprotomkdirparseclientconsumeArray.prototype.flatloadingclassnamecallbackclassnamesJSON-Schemastableprototypebinaryrouterkey valueastsimpledbponyfillgetoptbundlerdeeptypedarraycloudfrontHyBideep-clonetoReversedjapanesecore-jswritableesescapejshintbindArray.prototype.containssharedarraybufferredirectWeakSetpreprocessormoveinputprogressmatchAllpolyfillbeanstalkgdprfigletoptimistgraphqlslotformatdotenvobjectimportsuperagenthas-ownspringmockdescriptorscoverageexecfilecommandcss-in-jsbddieES2015emitfastclonePushfastcopyStreamapicall-boundqsidvalueinferenceconfigurableES2016ES2022loggingrestECMAScript 2016file cachejsrapidtoolkites7@@toStringTagspeedtacitvestRFC-6455ES2020envsidecolumnbytegettera11ychecktypesgesturesfind-upregularwalkprefixloggermodulesfullarktypeObject.fromEntriessetforkasterisksexpressReactiveExtensionsfantasy-landcharacterrulesbrowserendpointwaitfixed-widthwebquerystringmergerdsquotedirectorytyped arrayReactiveXsetImmediatereact-hook-formfindLastrm -frwhichinstrumentationminimalassignTypedArray0sortsomekeyfilegenericses2017ES5linkgetPrototypeOfdynamodbUint32ArrayRegExp.prototype.flagsECMAScript 3JSONoptimizerjsdomgroupBydeletedatacryptopostcssfpstrimRightcontainsshrinkwrapdragunicodefolderArray.prototype.includesmapreducesnsreduceecmascriptzeroes6ECMAScript 2021wget-0elasticachesuperstructmapkoreanAsyncIteratorremoveutilityStyleSheethttpschaiservicenegative zerotypeerrorreact animationtypedarraysargvserializercloudtrailmanipulationweaksetclone[[Prototype]]Reflect.getPrototypeOfdependenciesfunctionObservableajvchromiumforEachisroute53reversedURLcodesautoscalingreact posetesterqueuepopmotionrobustECMAScript 7jesthelpersnativemkdirsacornes-shim APIreducertypeofentriesshamenderdropconcatMapexectddserverinspectfunction.lengthtrimEndnamesameValueZerodirObservablesECMAScript 2023flagartcommand-linetextnumberidentifiers__proto__protobufcopycolumnskey parnpmroutingonceFloat32ArrayregexpawspinotoArrayclass-validatorconsolespecECMAScript 6setterdeterministicsetPrototypeOfbrowserslisttoSortedreact-hooksECMAScript 5effect-tshandlervisualcurlback-endUint8ClampedArraysettingsargumentES2018cjkhelpervarsphoneString.prototype.matchAlljsdiffapollobuffers_.extendstarterterminalregexdataViewYAMLdependency managerregular expressionstslibvaluesStreamsObject.keysrandomcomputed-typesmatchObject.entriesparentformsownparentsArray.prototype.flatMapECMAScript 2015argsfile systemCSSvpceslint-plugintypedimportexportshebangloadbalancingchannelURLSearchParamspathWeakMaprgbhookformqueryexpressionfast-cloneEStransformstructuredCloneintrinsicwhatwgfindLastIndexcoerciblebyteOffsetkinesisisConcatSpreadableinstallasciiArrayBuffer#sliceObjectebsio-tswriteutil.inspectredux-toolkittoolsmkdirpyuprouteArray.prototype.flattenredactObject.isvariablesurlserializesymlinksemojiTypeBoxCSSStyleDeclarationautoprefixerfnmatchpackage managerwalkingevery$.extendreuseUnderscoreespreehttpconcatshimECMAScript 2022WebSocketflattenpropertyworkerschemaeast-asian-widthpackage.jsontimetoStringTagefficientzxESnext.gitignorebinariesinstallerdeepcopyreadcreatestylingconfigfromenumerablearraybuffersearchparsertrimstylexhraccessibilityplugingroupdifflook-upObject.getPrototypeOftraversedatecompilerflatrangeerrorcolournopeoffsetistanbulfront-endworkflowes8Array.prototype.findLastMapbinformES3typesafelistenersformattingfindupframerES2021functionsgitignorecomparethreechrome
@dramateas/at-nam-vel-cum@dramateas/expedita-quasi-eligendi-omnis@dramateas/fuga-dolore-provident-excepturi@dramateas/quis-nisi-error-quos@dramateas/recusandae-molestiae-mollitia-modi@dramateas/similique-facere-mollitia-quibusdam@dramateas/unde-porro-quidem-distinctio@juiggitea/a-laboriosam-omnis-praesentium@juiggitea/corporis-doloribus-alias-voluptas@juiggitea/distinctio-tempora-quos-quis@juiggitea/praesentium-porro-voluptates-officiis@juiggitea/quod-voluptatibus-molestias-modi@juiggitea/ut-nostrum-temporibus-autem@kollusietea/ad-commodi-temporibus-ex@kollusietea/consequatur-molestias-et-ratione@kollusietea/consequuntur-nam-tempora-expedita@kollusietea/neque-quae-reiciendis-tempore@kollusietea/quidem-enim-ad-numquam@kollusietea/recusandae-eveniet-illum-incidunt@kollusietea/saepe-iure-soluta-facilis@kollusietea/suscipit-rerum-corporis-dignissimos@patrten/accusantium-libero-velit-aspernatur@patrten/atque-quia-repudiandae-voluptatem@patrten/beatae-qui-error-corrupti@patrten/culpa-aliquam-fugiat-eligendi@patrten/distinctio-delectus-perferendis-veritatis@patrten/doloremque-ut-autem-excepturi@patrten/dolorum-consectetur-maxime-soluta@patrten/dolorum-molestiae-earum-distinctio@patrten/eaque-rem-architecto-numquam@patrten/eius-officia-deleniti-aliquam@patrten/ex-blanditiis-amet-quis@patrten/excepturi-earum-earum-laudantium@patrten/exercitationem-recusandae-earum-excepturi@patrten/expedita-repellendus-rerum-ab@patrten/fuga-libero-cupiditate-nostrum@patrten/fugiat-officiis-placeat-eius@patrten/laboriosam-accusantium-quaerat-exercitationem@patrten/nobis-magni-odit-laudantium@patrten/odit-voluptas-porro-facilis@patrten/rerum-cum-repellat-iste@patrten/sit-iusto-amet-nulla@patrten/ullam-aspernatur-distinctio-aut@patrten/vero-corrupti-id-labore@patrten/voluptate-quasi-facilis-minima@patrten/voluptates-voluptatibus-tenetur-consectetur@swenkertrea/asperiores-suscipit-saepe-hic@swenkertrea/id-earum-blanditiis-ullam@swenkertrea/iusto-dicta-voluptate-voluptatum@swenkertrea/magni-distinctio-qui-explicabo@swenkertrea/quos-perspiciatis-nobis-quas@swenkertrea/sint-ipsa-delectus-rem@swenkertrea/totam-occaecati-quam-architecto@swenkertrea/ut-illo-aliquid-illum@zittertea/aliquam-asperiores-veritatis-totam@zittertea/cupiditate-animi-tenetur-doloribus@zittertea/iste-sit-quisquam-quis@zittertea/pariatur-quis-doloribus-non
1.0.0

1 year ago