New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

textlint-rule-max-comma

Package Overview
Dependencies
Maintainers
1
Versions
10
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

textlint-rule-max-comma - npm Package Compare versions

Comparing version 1.0.4 to 2.0.0

85

lib/textlint-rule-max-comma.js
// LICENSE : MIT
"use strict";
Object.defineProperty(exports, "__esModule", {
value: true
});
exports.default = _default;
var _unistUtilFilter = _interopRequireDefault(require("unist-util-filter"));
var _sentenceSplitter = require("sentence-splitter");
function _defineProperty(obj, key, value) { if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
var _textlintUtilToString = require("textlint-util-to-string");
var filter = require("unist-util-filter");
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
function countOfComma(text) {
return text.split(",").length - 1;
return text.split(",").length - 1;
}
var defaultOptions = {
// default: max comma count is 4
max: 4
// default: allowed command count
max: 4
};
module.exports = function (context) {
var options = arguments.length <= 1 || arguments[1] === undefined ? defaultOptions : arguments[1];
var maxComma = options.max || defaultOptions.max;
var Syntax = context.Syntax;
var RuleError = context.RuleError;
var report = context.report;
var getSource = context.getSource;
function _default(context) {
var options = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : defaultOptions;
var maxComma = options.max || defaultOptions.max;
var {
Syntax,
RuleError,
report,
getSource
} = context;
return {
[Syntax.Paragraph](node) {
var paragraphSentence = (0, _sentenceSplitter.splitAST)(node); // Remove Code node for avoiding false-positive in `CODE`
return _defineProperty({}, Syntax.Paragraph, function (node) {
var nodeWithoutCode = filter(node, function (node) {
return node.type !== Syntax.Code;
});
if (!nodeWithoutCode) {
return;
var paragraphSentenceWithoutNode = (0, _unistUtilFilter.default)(paragraphSentence, node => {
return node.type !== Syntax.Code;
}); // This `sum(0,1,2,3,4,5,6,7,8,9,10)` is ok
// → This is ok
var sentencesWithoutCode = paragraphSentenceWithoutNode.children.filter(node => node.type === _sentenceSplitter.Syntax.Sentence);
sentencesWithoutCode.forEach(sentence => {
var source = new _textlintUtilToString.StringSource(sentence);
var sentenceValue = source.toString();
var count = countOfComma(sentenceValue);
if (count > maxComma) {
var lastCommandIndex = sentenceValue.lastIndexOf(",");
report(node, new RuleError("This sentence exceeds the maximum count of comma. Maximum is ".concat(maxComma, "."), {
index: source.originalIndexFromIndex(lastCommandIndex)
}));
}
var texts = Array.isArray(nodeWithoutCode.children) ? nodeWithoutCode.children.map(function (child) {
return getSource(child);
}) : [];
var text = texts.join("");
var sentences = (0, _sentenceSplitter.split)(text).filter(function (node) {
return node.type === _sentenceSplitter.Syntax.Sentence;
});
sentences.forEach(function (sentence) {
var sentenceValue = sentence.value;
var count = countOfComma(sentenceValue);
if (count > maxComma) {
var paddingStart = {
line: sentence.loc.start.line - 1,
column: sentence.loc.start.column
};
report(node, new RuleError("This sentence exceeds the maximum count of comma. Maximum is " + maxComma + ".", paddingStart));
}
});
});
};
});
}
};
}
//# sourceMappingURL=textlint-rule-max-comma.js.map
{
"name": "textlint-rule-max-comma",
"version": "1.0.4",
"version": "2.0.0",
"description": "textlint rule that limit maxinum comma(,) count of sentence.",

@@ -14,6 +14,6 @@ "main": "lib/textlint-rule-max-comma.js",

"scripts": {
"build": "NODE_ENV=production babel src --out-dir lib --source-maps",
"watch": "babel src --out-dir lib --watch --source-maps",
"build": "textlint-scripts build",
"watch": "textlint-scripts build --watch",
"prepublish": "npm run --if-present build",
"test": "mocha"
"test": "textlint-scripts test"
},

@@ -35,12 +35,10 @@ "repository": {

"devDependencies": {
"babel-cli": "^6.7.7",
"babel-preset-es2015": "^6.6.0",
"babel-register": "^6.7.2",
"mocha": "^3.0.2",
"textlint-tester": "^2.0.0"
"textlint-scripts": "^3.0.0",
"textlint-tester": "^5.3.4"
},
"dependencies": {
"sentence-splitter": "^2.0.0",
"unist-util-filter": "^0.2.1"
"sentence-splitter": "^3.2.1",
"textlint-util-to-string": "^3.1.1",
"unist-util-filter": "^2.0.3"
}
}

@@ -1,2 +0,2 @@

# textlint-rule-max-comma [![Build Status](https://travis-ci.org/azu/textlint-rule-max-comma.svg?branch=master)](https://travis-ci.org/azu/textlint-rule-max-comma)
# textlint-rule-max-comma [![Actions Status: test](https://github.com/azu/textlint-rule-max-comma/workflows/test/badge.svg)](https://github.com/azu/textlint-rule-max-comma/actions?query=workflow%3A"test")

@@ -15,5 +15,7 @@ [textlint](http://textlint.github.io/ "textlint") rule is that limit maximum comma(,) count of sentence.

## Configure
## Options
Configure the maximum number of "," allowed in a sentence. The default is `4`
- `max`: maximum number of ","
- Default: `4`
- It means that report an error if the sentence include 5 or more `,`

@@ -26,3 +28,3 @@ Configure `"max"` value of the `.textlintrc` file.

"max-comma": {
"max" : 3
"max" : 4
}

@@ -39,3 +41,4 @@ }

- [azu/textlint-rule-max-ten: textlint rule that limit maxinum ten(、) count of sentence.](https://github.com/azu/textlint-rule-max-ten "azu/textlint-rule-max-ten: textlint rule that limit maxinum ten(、) count of sentence.")
- [textlint-rule-max-ten](https://github.com/textlint-ja/textlint-rule-max-ten)
- Japanese comma(`、`) edition

@@ -52,2 +55,2 @@ ## Contributing

MIT
MIT
// LICENSE : MIT
"use strict";
import {split, Syntax as SentenceSyntax} from "sentence-splitter";
const filter = require("unist-util-filter");
import filter from "unist-util-filter";
import { splitAST, Syntax as SentenceSyntax } from "sentence-splitter";
import { StringSource } from "textlint-util-to-string"
function countOfComma(text) {
return text.split(",").length - 1;
}
const defaultOptions = {
// default: max comma count is 4
// default: allowed command count
max: 4
};
module.exports = function(context, options = defaultOptions) {
export default function (context, options = defaultOptions) {
const maxComma = options.max || defaultOptions.max;
const {Syntax, RuleError, report, getSource} = context;
const { Syntax, RuleError, report, getSource } = context;
return {
[Syntax.Paragraph](node){
const nodeWithoutCode = filter(node, (node) => {
[Syntax.Paragraph](node) {
const paragraphSentence = splitAST(node)
// Remove Code node for avoiding false-positive in `CODE`
const paragraphSentenceWithoutNode = filter(paragraphSentence, (node) => {
return node.type !== Syntax.Code;
});
if (!nodeWithoutCode) {
return;
}
const texts = Array.isArray(nodeWithoutCode.children) ? nodeWithoutCode.children.map(child => {
return getSource(child);
}) : [];
const text = texts.join("");
const sentences = split(text).filter(node => node.type === SentenceSyntax.Sentence);
sentences.forEach(sentence => {
const sentenceValue = sentence.value;
// This `sum(0,1,2,3,4,5,6,7,8,9,10)` is ok
// → This is ok
const sentencesWithoutCode = paragraphSentenceWithoutNode
.children
.filter(node => node.type === SentenceSyntax.Sentence);
sentencesWithoutCode.forEach(sentence => {
const source = new StringSource(sentence);
const sentenceValue = source.toString();
const count = countOfComma(sentenceValue);
if (count > maxComma) {
const paddingStart = {
line: sentence.loc.start.line - 1,
column: sentence.loc.start.column
};
report(node, new RuleError(`This sentence exceeds the maximum count of comma. Maximum is ${maxComma}.`, paddingStart));
const lastCommandIndex = sentenceValue.lastIndexOf(",");
report(node, new RuleError(`This sentence exceeds the maximum count of comma. Maximum is ${maxComma}.`, {
index: source.originalIndexFromIndex(lastCommandIndex)
}));
}

@@ -41,2 +43,2 @@ });

}
};
}

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc