Coder Social home page Coder Social logo

leroydev / no-setting-array-properties-rule Goto Github PK

View Code? Open in Web Editor NEW
1.0 1.0 1.0 11 KB

A TSLint rule which forbids setting array properties, because they aren't handled by JSON.stringify.

License: MIT License

TypeScript 100.00%
tslint tslint-rules typescript

no-setting-array-properties-rule's Introduction

NPM version Downloads

No setting array properties rule

A TSLint rule which forbids setting array properties, because they aren't handled by JSON.stringify.

Description

When you call JSON.stringify on an array with custom properties, those properties aren't serialized. Example:

let arr: number[] = [1, 2];
const prop2: string = "prop2";

arr["prop1"] = "1";
arr[prop2] = "2";

JSON.stringify(arr); //results in [1,2]

This rule forbids property assignment and access on array types, so it forbids these two statements in the example above:

  • arr["prop1"] = "1";
  • arr[prop2] = "2";

Usage

  • Install it using npm install no-setting-array-properties-rule --save-dev.
  • Add it to your tslint.json, like this:
{
   "rulesDirectory": [
       "node_modules/no-setting-array-properties-rule/dist/src"
   ],
   "rules": {
       "no-setting-array-properties": true
   }
}

Note that this rule doesn't work in vscode-tslint at the moment, because it's a TypedRule. See this vscode-tslint issue for more details.

Changelog

See CHANGELOG.md.

no-setting-array-properties-rule's People

Contributors

leroydev avatar

Stargazers

 avatar

Watchers

 avatar

no-setting-array-properties-rule's Issues

Setting length

An array’s length property can be set, eg. to shorten the array. This should be allowed.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.