Skip to content

Commit

Permalink
fix(spectral-config): partially revert ESM (#724)
Browse files Browse the repository at this point in the history
* chore: more prettier cleanup

* Revert "feat(spectral): migrate to ESM (#718)"

This reverts commit b1a4ee5.

* revert: undo dependabot changes

* chore: revert dep changes

* chore: specify engines

* chore: hide test warnings

* fix: dynamically import alex

* chore: lint
  • Loading branch information
kanadgupta authored Aug 14, 2023
1 parent 8c43c69 commit c4161e3
Show file tree
Hide file tree
Showing 21 changed files with 71 additions and 71 deletions.
3 changes: 1 addition & 2 deletions packages/spectral-config/.eslintrc
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
{
"extends": "@readme/eslint-config",
// required for ESM
"rules": { "import/extensions": ["error", "always"] }
"parserOptions": { "ecmaVersion": 2020 }
}
5 changes: 2 additions & 3 deletions packages/spectral-config/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,13 @@
"name": "@readme/spectral-config",
"version": "3.0.2",
"description": "ReadMe coding standards for API documentation",
"exports": "./src/index.js",
"type": "module",
"main": "src/index.js",
"engines": {
"node": ">=16"
},
"scripts": {
"lint": "eslint .",
"test": "vitest run"
"test": "NODE_OPTIONS='--no-deprecation' vitest run"
},
"repository": {
"type": "git",
Expand Down
7 changes: 3 additions & 4 deletions packages/spectral-config/src/functions/alex.js
Original file line number Diff line number Diff line change
@@ -1,12 +1,11 @@
import { text } from 'alex';

/**
* Ensure that a given string has considerate and inclusive language.
*
* @see {@link https://alexjs.com/}
* @param {string} input
*/
export default function alex(input, options, context) {
module.exports = async function alex(input, options, context) {
const { text } = await import('alex');
const errors = text(input, { profanitySureness: 1 }).messages;

return errors
Expand All @@ -23,4 +22,4 @@ export default function alex(input, options, context) {
};
})
.filter(Boolean);
}
};
5 changes: 5 additions & 0 deletions packages/spectral-config/src/functions/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
/* eslint-disable global-require */
module.exports = {
alex: require('./alex'),
sentencePunctuation: require('./sentencePunctuation'),
};
4 changes: 2 additions & 2 deletions packages/spectral-config/src/functions/sentencePunctuation.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
*
* @param {string} input
*/
export default function sentencePunctuation(input) {
module.exports = function sentencePunctuation(input) {
if (!input) {
// Minor protection for when we have a `description` property as part of an endpoint payload,
// not a `description` of a schema entry.
Expand All @@ -19,4 +19,4 @@ export default function sentencePunctuation(input) {
}

return [];
}
};
28 changes: 10 additions & 18 deletions packages/spectral-config/src/index.js
Original file line number Diff line number Diff line change
@@ -1,27 +1,19 @@
import { oas } from '@stoplight/spectral-rulesets';
const { oas } = require('@stoplight/spectral-rulesets');

import alexComponentDescription from './rules/alex-component-description.js';
import alexComponentSummary from './rules/alex-component-summary.js';
import alexOperationDescription from './rules/alex-operation-description.js';
import alexOperationSummary from './rules/alex-operation-summary.js';
import alexParameter from './rules/alex-parameter.js';
import alexResponse from './rules/alex-response.js';
import descriptionSentencePunctuation from './rules/description-sentence-punctuation.js';
const rules = require('./rules');

const config = {
module.exports = {
extends: oas,
rules: {
'alex-component-description': alexComponentDescription,
'alex-component-summary': alexComponentSummary,
'alex-component-description': rules.alexComponentDescription,
'alex-component-summary': rules.alexComponentSummary,

'alex-operation-description': alexOperationDescription,
'alex-operation-summary': alexOperationSummary,
'alex-operation-description': rules.alexComponentDescription,
'alex-operation-summary': rules.alexOperationSummary,

'alex-parameter': alexParameter,
'alex-response': alexResponse,
'alex-parameter': rules.alexParameter,
'alex-response': rules.alexResponse,

'description-sentence-punctuation': descriptionSentencePunctuation,
'description-sentence-punctuation': rules.descriptionSentencePunctuation,
},
};

export default config;
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import alex from '../functions/alex.js';
const { alex } = require('../functions');

const rule = {
module.exports = {
description: 'Component schema description should have inclusive and considerate language.',
message: '{{error}}',
severity: 'error',
Expand All @@ -11,5 +11,3 @@ const rule = {
function: alex,
},
};

export default rule;
6 changes: 2 additions & 4 deletions packages/spectral-config/src/rules/alex-component-summary.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import alex from '../functions/alex.js';
const { alex } = require('../functions');

const rule = {
module.exports = {
description: 'Component schema summaries should have inclusive and considerate language.',
message: '{{error}}',
severity: 'error',
Expand All @@ -11,5 +11,3 @@ const rule = {
function: alex,
},
};

export default rule;
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import alex from '../functions/alex.js';
const { alex } = require('../functions');

const rule = {
module.exports = {
description: 'Operation descriptions should have inclusive and considerate language.',
message: '{{error}}',
severity: 'error',
Expand All @@ -11,5 +11,3 @@ const rule = {
function: alex,
},
};

export default rule;
6 changes: 2 additions & 4 deletions packages/spectral-config/src/rules/alex-operation-summary.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import alex from '../functions/alex.js';
const { alex } = require('../functions');

const rule = {
module.exports = {
description: 'Operation summaries should have inclusive and considerate language.',
message: '{{error}}',
severity: 'error',
Expand All @@ -11,5 +11,3 @@ const rule = {
function: alex,
},
};

export default rule;
6 changes: 2 additions & 4 deletions packages/spectral-config/src/rules/alex-parameter.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import alex from '../functions/alex.js';
const { alex } = require('../functions');

const rule = {
module.exports = {
description: 'Operation parameters should have inclusive and considerate language.',
message: '{{error}}',
severity: 'error',
Expand All @@ -11,5 +11,3 @@ const rule = {
function: alex,
},
};

export default rule;
6 changes: 2 additions & 4 deletions packages/spectral-config/src/rules/alex-response.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import alex from '../functions/alex.js';
const { alex } = require('../functions');

const rule = {
module.exports = {
description: 'Operation responses should have inclusive and considerate language.',
message: '{{error}}',
severity: 'error',
Expand All @@ -11,5 +11,3 @@ const rule = {
function: alex,
},
};

export default rule;
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import sentencePunctuation from '../functions/sentencePunctuation.js';
const { sentencePunctuation } = require('../functions');

const rule = {
module.exports = {
description: 'Descriptions should have ending punctuation.',
message: '{{description}}',
severity: 'info',
Expand All @@ -11,5 +11,3 @@ const rule = {
function: sentencePunctuation,
},
};

export default rule;
13 changes: 13 additions & 0 deletions packages/spectral-config/src/rules/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
/* eslint-disable global-require */
module.exports = {
alexComponentDescription: require('./alex-component-description'),
alexComponentSummary: require('./alex-component-summary'),

alexOperationDescription: require('./alex-operation-description'),
alexOperationSummary: require('./alex-operation-summary'),

alexParameter: require('./alex-parameter'),
alexResponse: require('./alex-response'),

descriptionSentencePunctuation: require('./description-sentence-punctuation'),
};
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
import { makeCopy, severityCodes, testRule } from '@ibm-cloud/openapi-ruleset/test/utils/index.js';
import { makeCopy, severityCodes, testRule } from '@ibm-cloud/openapi-ruleset/test/utils';
import readme from '@readme/oas-examples/3.0/json/readme.json';
import { describe, it, expect } from 'vitest';

import rule from '../src/rules/alex-component-description.js';
const { alexComponentDescription } = require('../src/rules');

const rule = alexComponentDescription;
const ruleId = 'alex-component-description';
const expectedSeverity = severityCodes.error;
const expectedErrorMsg = 'Don’t use `fucking`, it’s profane';
Expand Down
5 changes: 3 additions & 2 deletions packages/spectral-config/test/alex-component-summary.test.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
import { makeCopy, severityCodes, testRule } from '@ibm-cloud/openapi-ruleset/test/utils/index.js';
import { makeCopy, severityCodes, testRule } from '@ibm-cloud/openapi-ruleset/test/utils';
import readme from '@readme/oas-examples/3.0/json/readme.json';
import { describe, it, expect } from 'vitest';

import rule from '../src/rules/alex-component-summary.js';
const { alexComponentSummary } = require('../src/rules');

const rule = alexComponentSummary;
const ruleId = 'alex-component-summary';
const expectedSeverity = severityCodes.error;
const expectedErrorMsg = 'Don’t use `fucking`, it’s profane';
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
import { makeCopy, severityCodes, testRule } from '@ibm-cloud/openapi-ruleset/test/utils/index.js';
import { makeCopy, severityCodes, testRule } from '@ibm-cloud/openapi-ruleset/test/utils';
import readme from '@readme/oas-examples/3.0/json/readme.json';
import { describe, it, expect } from 'vitest';

import rule from '../src/rules/alex-operation-description.js';
const { alexOperationDescription } = require('../src/rules');

const rule = alexOperationDescription;
const ruleId = 'alex-operation-description';
const expectedSeverity = severityCodes.error;
const expectedErrorMsg = 'Don’t use `fucking`, it’s profane';
Expand Down
5 changes: 3 additions & 2 deletions packages/spectral-config/test/alex-operation-summary.test.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
import { makeCopy, severityCodes, testRule } from '@ibm-cloud/openapi-ruleset/test/utils/index.js';
import { makeCopy, severityCodes, testRule } from '@ibm-cloud/openapi-ruleset/test/utils';
import readme from '@readme/oas-examples/3.0/json/readme.json';
import { describe, it, expect } from 'vitest';

import rule from '../src/rules/alex-operation-summary.js';
const { alexOperationSummary } = require('../src/rules');

const rule = alexOperationSummary;
const ruleId = 'alex-operation-summary';
const expectedSeverity = severityCodes.error;
const expectedErrorMsg = 'Don’t use `fucking`, it’s profane';
Expand Down
5 changes: 3 additions & 2 deletions packages/spectral-config/test/alex-parameter.test.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
import { makeCopy, severityCodes, testRule } from '@ibm-cloud/openapi-ruleset/test/utils/index.js';
import { makeCopy, severityCodes, testRule } from '@ibm-cloud/openapi-ruleset/test/utils';
import readme from '@readme/oas-examples/3.0/json/readme.json';
import { describe, it, expect } from 'vitest';

import rule from '../src/rules/alex-parameter.js';
const { alexParameter } = require('../src/rules');

const rule = alexParameter;
const ruleId = 'alex-parameter';
const expectedSeverity = severityCodes.error;
const expectedErrorMsg = 'Don’t use `fucking`, it’s profane';
Expand Down
5 changes: 3 additions & 2 deletions packages/spectral-config/test/alex-response.test.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
import { makeCopy, severityCodes, testRule } from '@ibm-cloud/openapi-ruleset/test/utils/index.js';
import { makeCopy, severityCodes, testRule } from '@ibm-cloud/openapi-ruleset/test/utils';
import readme from '@readme/oas-examples/3.0/json/readme.json';
import { describe, it, expect } from 'vitest';

import rule from '../src/rules/alex-response.js';
const { alexResponse } = require('../src/rules');

const rule = alexResponse;
const ruleId = 'alex-response';
const expectedSeverity = severityCodes.error;
const expectedErrorMsg = 'Don’t use `fucking`, it’s profane';
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
import { makeCopy, severityCodes, testRule } from '@ibm-cloud/openapi-ruleset/test/utils/index.js';
import { makeCopy, severityCodes, testRule } from '@ibm-cloud/openapi-ruleset/test/utils';
import readme from '@readme/oas-examples/3.0/json/readme.json';
import { describe, it, expect } from 'vitest';

import rule from '../src/rules/description-sentence-punctuation.js';
const { descriptionSentencePunctuation } = require('../src/rules');

const rule = descriptionSentencePunctuation;
const ruleId = 'description-sentence-punctuation';
const expectedSeverity = severityCodes.info;
const expectedErrorMsg = 'Descriptions should have ending punctuation.';
Expand Down

0 comments on commit c4161e3

Please sign in to comment.