Skip to content

Commit

Permalink
Merge pull request #3 from textlint-rule/update-2021-05-01
Browse files Browse the repository at this point in the history
chore(deps): update dependencies
  • Loading branch information
azu committed May 1, 2021
2 parents 645b16d + 0044ace commit 0bc3d86
Show file tree
Hide file tree
Showing 9 changed files with 3,140 additions and 1,961 deletions.
2 changes: 2 additions & 0 deletions .githooks/pre-commit
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
#!/bin/sh
npx --no-install lint-staged
20 changes: 20 additions & 0 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
name: test
on: [push, pull_request]
jobs:
test:
name: "Test on Node.js ${{ matrix.node-version }}"
runs-on: ubuntu-latest
strategy:
matrix:
node-version: [12, 14]
steps:
- name: checkout
uses: actions/checkout@v2
- name: setup Node.js ${{ matrix.node-version }}
uses: actions/setup-node@v2
with:
node-version: ${{ matrix.node-version }}
- name: Install
run: yarn install
- name: Test
run: yarn test
3 changes: 0 additions & 3 deletions .travis.yml

This file was deleted.

2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# @textlint-rule/textlint-rule-no-invalid-control-character [![Build Status](https://travis-ci.org/textlint-rule/textlint-rule-no-invalid-control-character.svg?branch=master)](https://travis-ci.org/textlint-rule/textlint-rule-no-invalid-control-character)
# @textlint-rule/textlint-rule-no-invalid-control-character [![Actions Status: test](https://github.com/textlint-rule/textlint-rule-no-invalid-control-character/workflows/test/badge.svg)](https://github.com/textlint-rule/textlint-rule-no-invalid-control-character/actions?query=workflow%3A"test")

textlint rule check invalid control character in the document.

Expand Down
21 changes: 10 additions & 11 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,12 +16,11 @@
"main": "lib/textlint-rule-no-invalid-control-character.js",
"scripts": {
"test": "textlint-scripts test",
"prettier": "prettier --write \"**/*.{js,jsx,ts,tsx,css}\"",
"precommit": "lint-staged",
"postcommit": "git reset",
"prepublish": "npm run --if-present build",
"build": "textlint-scripts build",
"watch": "textlint-scripts build --watch"
"watch": "textlint-scripts build --watch",
"format": "prettier --write \"**/*.{js,jsx,ts,tsx,css}\"",
"prepare": "git config --local core.hooksPath .githooks"
},
"keywords": [
"textlintrule"
Expand All @@ -35,19 +34,19 @@
},
"homepage": "https://github.com/textlint-rule/textlint-rule-no-invalid-control-character",
"devDependencies": {
"husky": "^0.14.3",
"lint-staged": "^6.0.0",
"prettier": "^1.9.2",
"textlint-scripts": "^1.4.1"
"lint-staged": "^10.5.4",
"prettier": "^2.2.1",
"textlint-scripts": "^3.0.0"
},
"prettier": {
"singleQuote": false,
"printWidth": 120,
"tabWidth": 4
"tabWidth": 4,
"trailingComma": "none"
},
"lint-staged": {
"*.{js,jsx,ts,tsx,css}": [
"prettier --write",
"git add"
"prettier --write"
]
},
"dependencies": {
Expand Down
2 changes: 1 addition & 1 deletion src/CONTROL_CHARACTERS.js
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,7 @@ const CONTROL_CHARACTERS = [
];

// except
const INVALID_CONTROL_CHARACTERS = CONTROL_CHARACTERS.filter(CONTROL_CHARACTER => {
const INVALID_CONTROL_CHARACTERS = CONTROL_CHARACTERS.filter((CONTROL_CHARACTER) => {
const code = CONTROL_CHARACTER.code;
return code !== "\r" && code !== "\n" && code !== "\t";
});
Expand Down
14 changes: 7 additions & 7 deletions src/textlint-rule-no-invalid-control-character.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,14 +9,14 @@ import { CONTROL_CHARACTERS } from "./CONTROL_CHARACTERS";
* @param {string} str
* @return {string}
*/
const unicodeEscape = str => {
return str.replace(/./g, c => {
const unicodeEscape = (str) => {
return str.replace(/./g, (c) => {
return `\\u${`000${c.charCodeAt(0).toString(16)}`.substr(-4)}`;
});
};

const getName = char => {
const matchChar = CONTROL_CHARACTERS.find(CONTROL_CHARACTER => CONTROL_CHARACTER.code === char);
const getName = (char) => {
const matchChar = CONTROL_CHARACTERS.find((CONTROL_CHARACTER) => CONTROL_CHARACTER.code === char);
if (!matchChar) {
return "";
}
Expand All @@ -37,19 +37,19 @@ const reporter = (context, options = {}) => {
const allow = options.allow || DEFAULT_OPTION.allow;
const checkCode = options.checkCode !== undefined ? options.checkCode : DEFAULT_OPTION.checkCode;
const checkImage = options.checkImage !== undefined ? options.checkImage : DEFAULT_OPTION.checkImage;
const checkNode = node => {
const checkNode = (node) => {
const text = getSource(node);
// Ignore \r \n \t
const controlCharacterPattern = /([\x00-\x08\x0B\x0C\x0E-\x1F\x7F])/g;
/**
* @type {Array<{match:string, sub:string[], index:number}>}
*/
const results = execall(controlCharacterPattern, text);
results.forEach(result => {
results.forEach((result) => {
const index = result.index;
const char = result.sub[0];
// if allow the `char`, ignore it
if (allow.some(allowChar => allowChar === char)) {
if (allow.some((allowChar) => allowChar === char)) {
return;
}
const name = getName(char);
Expand Down
2 changes: 1 addition & 1 deletion test/textlint-rule-no-invalid-control-character-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ const tester = new TextLintTester();
const rule = require("../src/textlint-rule-no-invalid-control-character");
import { INVALID_CONTROL_CHARACTERS } from "../src/CONTROL_CHARACTERS";

const invalid = INVALID_CONTROL_CHARACTERS.map(character => {
const invalid = INVALID_CONTROL_CHARACTERS.map((character) => {
return {
text: `${character.code}:${character.name}`,
output: `:${character.name}`,
Expand Down
Loading

0 comments on commit 0bc3d86

Please sign in to comment.