sindresorhus/eslint-plugin-unicorn

Rule proposal: `no-top-level-side-effects`

Open

#1.661 aberto em 24 de dez. de 2021

Ver no GitHub
 (11 comments) (7 reactions) (0 assignees)JavaScript (468 forks)user submission
:dollar: Funded on Issuehunthelp wantednew rule

Métricas do repositório

Stars
 (5.022 stars)
Métricas de merge de PR
 (Mesclagem média 1d 8h) (6 fundiu PRs em 30d)

Description

Description

Opinionated, difficult/impossible to implement, and likely super annoying in practice.

Reasoning: importing a file should not have side effects

Related rules:

Fail

document.title = 'gone'

Pass

export function init () {
  document.title = 'gone'
}
function init () {
  document.title = 'gone'
}

// Optional? Still a side effect, but at least it's wrapped
// and not lost between many function declarations.
// Maybe a single, unassigned function call per file could be allowed
init(); 
// Optional? Assignments could be considered side-effect free for the sake of usability
const details = new Map();
const response = fetch(); // even if they're not, really
const memoizedFetch = mem(fetch);
// in ./polyfill.js

// Optional? Some exceptions could be made by filename 
document.title = 'gone'

Backers (Total: $20.00)

Submitted pull Requests


Become a backer now!

Or submit a pull request to get the deposits!

Tips

Guia do colaborador