Skip to content

Commit

Permalink
feat: Upgrade dependencies, build setup, convert to ESM
Browse files Browse the repository at this point in the history
BREAKING CHANGE:

- The modules is exported as ESM
- Node.js 20 is the minimum supported version
  • Loading branch information
sapegin committed Jun 9, 2024
1 parent 07977d8 commit 7b7c4af
Show file tree
Hide file tree
Showing 11 changed files with 4,625 additions and 5,541 deletions.
20 changes: 20 additions & 0 deletions .github/workflows/.github/workflows/release.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
name: Semantic Release
on:
push:
branches:
- master
jobs:
release:
name: Release
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: actions/setup-node@v4
with:
node-version-file: .nvmrc
cache: 'npm'
- run: npm ci
- env:
GITHUB_TOKEN: ${{ secrets.GH_TOKEN }}
NPM_TOKEN: ${{ secrets.NPM_TOKEN }}
run: npx semantic-release
22 changes: 0 additions & 22 deletions .github/workflows/dependabot.yml

This file was deleted.

19 changes: 19 additions & 0 deletions .github/workflows/node.js.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
name: Node.js CI
on:
push:
branches:
- master
pull_request:
branches:
- master
jobs:
build:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: actions/setup-node@v4
with:
node-version-file: .nvmrc
cache: 'npm'
- run: npm ci
- run: npm test
1 change: 1 addition & 0 deletions .nvmrc
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
v20
13 changes: 0 additions & 13 deletions .travis.yml

This file was deleted.

19 changes: 1 addition & 18 deletions Contributing.md
Original file line number Diff line number Diff line change
@@ -1,28 +1,11 @@
# How to contribute

I love pull requests. And following this simple guidelines will make your pull request easier to merge.

## Submitting pull requests

1. Create a new branch, please don’t work in master directly.
2. Add failing tests (if there’re any tests in project) for the change you want to make. Run tests (see below) to see the tests fail.
3. Hack on.
4. Run tests to see if the tests pass. Repeat steps 2–4 until done.
5. Update the documentation to reflect any changes.
6. Push to your fork and submit a pull request.
Bug fixes are welcome, but not new features. [See more details](https://sapegin.me/blog/healthy-open-source/).

## JavaScript code style

[See here](https://github.com/tamiadev/eslint-config-tamia#code-style-at-a-glance).

## Other notes

- If you have commit access to repo and want to make big change or not sure about something, make a new branch and open pull request.
- Don’t commit generated files: compiled from Stylus CSS, minified JavaScript, etc.
- Don’t change version number and changelog.
- Install [EditorConfig](http://editorconfig.org/) plugin for your code editor.
- Feel free to [ask me](http://sapegin.me) anything you need.

## Building and running tests

Install dependencies:
Expand Down
4 changes: 2 additions & 2 deletions Readme.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# textlint-rule-diacritics

[![textlint fixable rule](https://img.shields.io/badge/textlint-fixable-green.svg?style=social)](https://textlint.github.io/) [![Build Status](https://travis-ci.org/sapegin/textlint-rule-diacritics.svg)](https://travis-ci.org/sapegin/textlint-rule-diacritics) [![npm](https://img.shields.io/npm/v/textlint-rule-diacritics.svg)](https://www.npmjs.com/package/textlint-rule-diacritics)
[![textlint fixable rule](https://img.shields.io/badge/textlint-fixable-green.svg?style=social)](https://textlint.github.io/) [![npm](https://img.shields.io/npm/v/textlint-rule-diacritics.svg)](https://www.npmjs.com/package/textlint-rule-diacritics) [![Node.js CI status](https://github.com/sapegin/textlint-rule-diacritics/workflows/Node.js%20CI/badge.svg)](https://github.com/sapegin/textlint-rule-diacritics/actions)

[Textlint](https://github.com/textlint/textlint) rule to check and fix the correct usage of diacritics.

Expand Down Expand Up @@ -62,7 +62,7 @@ The change log can be found on the [Releases page](https://github.com/sapegin/te

## Contributing

Everyone is welcome to contribute. Please take a moment to review the [contributing guidelines](Contributing.md).
Bug fixes are welcome, but not new features. Please take a moment to review the [contributing guidelines](Contributing.md).

## Sponsoring

Expand Down
8 changes: 5 additions & 3 deletions index.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
const fs = require('fs');
const stripJsonComments = require('strip-json-comments');
const matchCasing = require('match-casing');
import fs from 'fs';
import stripJsonComments from 'strip-json-comments';
import { matchCasing } from 'match-casing';

const DEFAULT_OPTIONS = {
words: [],
Expand Down Expand Up @@ -43,6 +43,8 @@ function reporter(context, options = {}) {
continue;
}

console.log('🦀 replacement', replacement);

const index = match.index;
const range = [index, index + matched.length];
const fix = fixer.replaceTextRange(range, replacement);
Expand Down
31 changes: 16 additions & 15 deletions test.js → index.test.js
Original file line number Diff line number Diff line change
@@ -1,23 +1,24 @@
const TextLintTester = require('textlint-tester');
const rule = require('./index');
import { describe, test, expect } from 'vitest';
import TextLintTester from 'textlint-tester';
import rule from './index';

const { getPattern, getPatterns, getRegExp, getCorrection } = rule.test;
const tester = new TextLintTester();

describe('getPattern', () => {
it('should replace all symbols from groups with corresponding regexp patterns', () => {
test('should replace all symbols from groups with corresponding regexp patterns', () => {
const result = getPattern('résumé');
expect(result).toBe('r[éèêëe]sum[éèêëe]');
});

it('should replace apostrophes with corresponding regexp patterns', () => {
test('should replace apostrophes with corresponding regexp patterns', () => {
const result = getPattern('d’état');
expect(result).toBe("d[’'][éèêëe]tat");
});
});

describe('getPatterns', () => {
it('should return an array of patterns', () => {
test('should return an array of patterns', () => {
const words = ['décor', 'résumé'];
const result = getPatterns(words);
expect(result).toHaveLength(words.length);
Expand All @@ -26,35 +27,35 @@ describe('getPatterns', () => {

describe('getRegExp', () => {
const patterns = ['r[éèêëe]sum[éèêëe]', 'd[éèêëe]cor'];
it('should match a pattern as a full word', () => {
test('should match a pattern as a full word', () => {
const result = getRegExp(patterns).exec('My resume is good');
expect(result).toBeTruthy();
expect(result[1]).toBe('resume');
});

it('should not match a pattern only at the beginning of a word', () => {
test('should not match a pattern only at the beginning of a word', () => {
const result = getRegExp(patterns).exec('All resumes are terrible');
expect(result).toBeFalsy();
});

it('should not match a pattern in the middle of a word', () => {
test('should not match a pattern in the middle of a word', () => {
const result = getRegExp(patterns).exec('Foo undecorated bar');
expect(result).toBeFalsy();
});

it('should match a pattern if some marks are present', () => {
test('should match a pattern if some marks are present', () => {
const result = getRegExp(patterns).exec('My résume is good');
expect(result).toBeTruthy();
expect(result[1]).toBe('résume');
});

it('should match a pattern regardless of its case', () => {
test('should match a pattern regardless of its case', () => {
const result = getRegExp(patterns).exec('Resume is good');
expect(result).toBeTruthy();
expect(result[1]).toBe('Resume');
});

it('should match several patterns', () => {
test('should match several patterns', () => {
const regexp = getRegExp(patterns);
const text = 'My résume and your décor';
const result1 = regexp.exec(text);
Expand All @@ -69,22 +70,22 @@ describe('getRegExp', () => {
describe('getCorrection', () => {
const words = ['crème fraîche', 'crêpe', 'crêpes', 'débutante'];

it('should return a correct word', () => {
test('should return a correct word', () => {
const result = getCorrection(words, 'crepe');
expect(result).toBe('crêpe');
});

it('should keep suffix', () => {
test('should keep suffix', () => {
const result = getCorrection(words, 'crepes');
expect(result).toBe('crêpes');
});

it('should keep original case', () => {
test('should keep original case', () => {
const result = getCorrection(words, 'Crepe');
expect(result).toBe('Crêpe');
});

it('should return false if match not found', () => {
test('should return false if match not found', () => {
const result = getCorrection(words, 'pizza');
expect(result).toBeFalsy();
});
Expand Down
Loading

0 comments on commit 7b7c4af

Please sign in to comment.