Skip to content

Commit f1f30c3

Browse files
authored
Switch create-rule and integration test to module (#1205)
1 parent 5a4dc90 commit f1f30c3

File tree

5 files changed

+34
-33
lines changed

5 files changed

+34
-33
lines changed

package.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,9 +15,9 @@
1515
},
1616
"scripts": {
1717
"test": "xo && nyc ava",
18-
"create-rule": "node ./scripts/create-rule.js && npm run generate-rules-table",
18+
"create-rule": "node ./scripts/create-rule.mjs && npm run generate-rules-table",
1919
"run-rules-on-codebase": "node ./test/run-rules-on-codebase/lint.mjs",
20-
"integration": "node ./test/integration/test.js",
20+
"integration": "node ./test/integration/test.mjs",
2121
"smoke": "eslint-remote-tester --config ./test/smoke/eslint-remote-tester.config.js",
2222
"generate-rules-table": "node ./scripts/generate-rules-table.mjs"
2323
},
Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,13 @@
11
#!/usr/bin/env node
2-
'use strict';
2+
import fs from 'node:fs';
3+
import path from 'node:path';
4+
import {fileURLToPath} from 'node:url';
5+
import enquirer from 'enquirer';
6+
import {template} from 'lodash-es';
7+
import execa from 'execa';
38

4-
const fs = require('fs');
5-
const path = require('path');
6-
const enquirer = require('enquirer');
7-
const {template} = require('lodash');
8-
const execa = require('execa');
9-
10-
const ROOT = path.join(__dirname, '..');
9+
const dirname = path.dirname(fileURLToPath(import.meta.url));
10+
const ROOT = path.join(dirname, '..');
1111

1212
function checkFiles(ruleId) {
1313
const files = [
@@ -24,7 +24,7 @@ function checkFiles(ruleId) {
2424
}
2525

2626
function renderTemplate({source, target, data}) {
27-
const templateFile = path.join(__dirname, `template/${source}`);
27+
const templateFile = path.join(dirname, `template/${source}`);
2828
const targetFile = path.join(ROOT, target);
2929
const templateContent = fs.readFileSync(templateFile, 'utf8');
3030

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,12 @@
1-
'use strict';
2-
const path = require('path');
1+
import path from 'node:path';
2+
import {fileURLToPath} from 'node:url';
33

4-
module.exports = [
4+
const dirname = path.dirname(fileURLToPath(import.meta.url));
5+
6+
export default [
57
{
68
name: 'fixtures-local',
7-
location: path.join(__dirname, 'fixtures-local')
9+
location: path.join(dirname, 'fixtures-local')
810
},
911
{
1012
repository: 'https://github.com/avajs/ava',
Lines changed: 15 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,15 @@
11
#!/usr/bin/env node
2-
'use strict';
3-
const fs = require('fs');
4-
const path = require('path');
5-
const Listr = require('listr');
6-
const execa = require('execa');
7-
const chalk = require('chalk');
8-
const {isCI} = require('ci-info');
9-
const mem = require('mem');
10-
const allProjects = require('./projects');
11-
2+
import fs from 'node:fs';
3+
import path from 'node:path';
4+
import {fileURLToPath} from 'node:url';
5+
import Listr from 'listr';
6+
import execa from 'execa';
7+
import chalk from 'chalk';
8+
import {isCI} from 'ci-info';
9+
import mem from 'mem';
10+
import allProjects from './projects.mjs';
11+
12+
const dirname = path.dirname(fileURLToPath(import.meta.url));
1213
const projectsArguments = process.argv.slice(2);
1314
const projects = projectsArguments.length === 0 ?
1415
allProjects :
@@ -35,7 +36,7 @@ const makeEslintTask = (project, destination) => {
3536
'--format',
3637
'json',
3738
'--config',
38-
path.join(__dirname, 'config.js')
39+
path.join(dirname, 'config.js')
3940
];
4041

4142
for (const pattern of project.ignore) {
@@ -46,7 +47,7 @@ const makeEslintTask = (project, destination) => {
4647
let stdout;
4748
let processError;
4849
try {
49-
({stdout} = await execa('npx', arguments_, {cwd: destination, localDir: __dirname}));
50+
({stdout} = await execa('npx', arguments_, {cwd: destination, localDir: dirname}));
5051
} catch (error) {
5152
({stdout} = error);
5253
processError = error;
@@ -89,7 +90,7 @@ const makeEslintTask = (project, destination) => {
8990
const getBranch = mem(async dirname => (await execa('git', ['branch', '--show-current'], {cwd: dirname})).stdout);
9091

9192
const execute = project => {
92-
const destination = project.location || path.join(__dirname, 'fixtures', project.name);
93+
const destination = project.location || path.join(dirname, 'fixtures', project.name);
9394

9495
return new Listr([
9596
{
@@ -120,7 +121,7 @@ const execute = project => {
120121
const list = new Listr([
121122
{
122123
title: 'Setup',
123-
task: () => execa('npm', ['install'], {cwd: __dirname})
124+
task: () => execa('npm', ['install'], {cwd: dirname})
124125
},
125126
{
126127
title: 'Integration tests',

test/run-rules-on-codebase/lint.mjs

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -38,11 +38,9 @@ const eslint = new ESLint({
3838
// ESLint don't support module
3939
'rules/**/*.js',
4040
'index.js',
41+
'test/integration/config.js',
4142
// `eslint-remote-tester` only support cjs config
42-
'test/smoke/eslint-remote-tester.config.js',
43-
// TODO: Switch to module
44-
'scripts/create-rule.js',
45-
'test/integration/**/*'
43+
'test/smoke/eslint-remote-tester.config.js'
4644
],
4745
rules: {
4846
'unicorn/prefer-module': 'off'

0 commit comments

Comments
 (0)