|
12 | 12 | const path = require("path"), |
13 | 13 | { unIndent } = require("../../_utils"), |
14 | 14 | rule = require("../../../lib/rules/comma-dangle"), |
15 | | - { RuleTester } = require("../../../lib/rule-tester"); |
| 15 | + { RuleTester } = require("../../../lib/rule-tester"), |
| 16 | + FlatRuleTester = require("../../../lib/rule-tester/flat-rule-tester"); |
16 | 17 |
|
17 | 18 | //------------------------------------------------------------------------------ |
18 | 19 | // Helpers |
@@ -279,6 +280,14 @@ ruleTester.run("comma-dangle", rule, { |
279 | 280 | code: "function foo(a,\nb) {}", |
280 | 281 | options: ["always-multiline"] |
281 | 282 | }, |
| 283 | + { |
| 284 | + code: "foo(a,\nb\n)", |
| 285 | + options: ["always-multiline"] |
| 286 | + }, |
| 287 | + { |
| 288 | + code: "function foo(a,\nb\n) {}", |
| 289 | + options: ["always-multiline"] |
| 290 | + }, |
282 | 291 | { |
283 | 292 | code: "foo(a,\nb)", |
284 | 293 | options: ["always-multiline"] |
@@ -321,6 +330,16 @@ ruleTester.run("comma-dangle", rule, { |
321 | 330 | options: ["always-multiline"], |
322 | 331 | parserOptions: { ecmaVersion: 7 } |
323 | 332 | }, |
| 333 | + { |
| 334 | + code: "function foo(a,\nb\n) {}", |
| 335 | + options: ["always-multiline"], |
| 336 | + parserOptions: { ecmaVersion: 7 } |
| 337 | + }, |
| 338 | + { |
| 339 | + code: "foo(a,\nb\n)", |
| 340 | + options: ["always-multiline"], |
| 341 | + parserOptions: { ecmaVersion: 7 } |
| 342 | + }, |
324 | 343 | { |
325 | 344 | code: "function foo(a,\nb) {}", |
326 | 345 | options: ["only-multiline"], |
@@ -1853,3 +1872,100 @@ let d = 0;export {d,}; |
1853 | 1872 | } |
1854 | 1873 | ] |
1855 | 1874 | }); |
| 1875 | + |
| 1876 | +const flatRuleTester = new FlatRuleTester(); |
| 1877 | + |
| 1878 | +// https://github.com/eslint/eslint/issues/16442 |
| 1879 | +flatRuleTester.run("comma-dangle", rule, { |
| 1880 | + valid: [ |
| 1881 | + { |
| 1882 | + code: "function f(\n a,\n b\n) {}", |
| 1883 | + options: ["always-multiline"], |
| 1884 | + languageOptions: { |
| 1885 | + ecmaVersion: 5, |
| 1886 | + sourceType: "script" |
| 1887 | + } |
| 1888 | + }, |
| 1889 | + { |
| 1890 | + code: "f(\n a,\n b\n);", |
| 1891 | + options: ["always-multiline"], |
| 1892 | + languageOptions: { |
| 1893 | + ecmaVersion: 5, |
| 1894 | + sourceType: "script" |
| 1895 | + } |
| 1896 | + }, |
| 1897 | + { |
| 1898 | + code: "function f(\n a,\n b\n) {}", |
| 1899 | + options: ["always-multiline"], |
| 1900 | + languageOptions: { |
| 1901 | + ecmaVersion: 2016 |
| 1902 | + } |
| 1903 | + }, |
| 1904 | + { |
| 1905 | + code: "f(\n a,\n b\n);", |
| 1906 | + options: ["always-multiline"], |
| 1907 | + languageOptions: { |
| 1908 | + ecmaVersion: 2016 |
| 1909 | + } |
| 1910 | + } |
| 1911 | + ], |
| 1912 | + |
| 1913 | + invalid: [ |
| 1914 | + { |
| 1915 | + code: "function f(\n a,\n b\n) {}", |
| 1916 | + output: "function f(\n a,\n b,\n) {}", |
| 1917 | + options: ["always-multiline"], |
| 1918 | + languageOptions: { |
| 1919 | + ecmaVersion: 2017 |
| 1920 | + }, |
| 1921 | + errors: [{ |
| 1922 | + messageId: "missing", |
| 1923 | + type: "Identifier", |
| 1924 | + line: 3, |
| 1925 | + column: 3 |
| 1926 | + }] |
| 1927 | + }, |
| 1928 | + { |
| 1929 | + code: "f(\n a,\n b\n);", |
| 1930 | + output: "f(\n a,\n b,\n);", |
| 1931 | + options: ["always-multiline"], |
| 1932 | + languageOptions: { |
| 1933 | + ecmaVersion: 2017 |
| 1934 | + }, |
| 1935 | + errors: [{ |
| 1936 | + messageId: "missing", |
| 1937 | + type: "Identifier", |
| 1938 | + line: 3, |
| 1939 | + column: 3 |
| 1940 | + }] |
| 1941 | + }, |
| 1942 | + { |
| 1943 | + code: "function f(\n a,\n b\n) {}", |
| 1944 | + output: "function f(\n a,\n b,\n) {}", |
| 1945 | + options: ["always-multiline"], |
| 1946 | + languageOptions: { |
| 1947 | + ecmaVersion: "latest" |
| 1948 | + }, |
| 1949 | + errors: [{ |
| 1950 | + messageId: "missing", |
| 1951 | + type: "Identifier", |
| 1952 | + line: 3, |
| 1953 | + column: 3 |
| 1954 | + }] |
| 1955 | + }, |
| 1956 | + { |
| 1957 | + code: "f(\n a,\n b\n);", |
| 1958 | + output: "f(\n a,\n b,\n);", |
| 1959 | + options: ["always-multiline"], |
| 1960 | + languageOptions: { |
| 1961 | + ecmaVersion: "latest" |
| 1962 | + }, |
| 1963 | + errors: [{ |
| 1964 | + messageId: "missing", |
| 1965 | + type: "Identifier", |
| 1966 | + line: 3, |
| 1967 | + column: 3 |
| 1968 | + }] |
| 1969 | + } |
| 1970 | + ] |
| 1971 | +}); |
0 commit comments